1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
.TH GOLF 2gg $VERSION $DATE Development Tools
.SH NAME
get-req \- (request-information)
.SH PURPOSE
Obtain data that describes the input request.
.SH SYNTAX
.RS 4
.EX
get-req \\
errno | error | cookie-count | cookie <cookie index> \\
| arg-count | arg-value <arg index> \\
| header <header> | referring-url | method \\
| content-type | trace-file | process-id | name \\
| external-call | directory | source-file
to <variable>
.EE
.RE
.SH DESCRIPTION
Information related to an input request can be obtained with get-req statement and the result stored into <variable> (in "to" clause). The following can be obtained (all are strings except where stated otherwise):
.RS 4
\[bu]
"errno" obtains the integer value of operating system "errno" tied to a last Golf statement that can return a status code. The "errno" value is saved internally; and restored here. It means that if "errno" changed for whatever reason since such Golf statement (such as with \fBcall-extended\fP), you will still obtain the correct value. See \fBerror-code\fP for an example. Note that errno value is undefined if there is no error, and can be 0 if the error is reported by Golf and not by operating system.
.RE
.RS 4
\[bu]
"error" returns the error message that correlates to "errno" value.
.RE
.RS 4
\[bu]
"cookie-count" returns the number of cookies. This means any cookies received from the client plus any cookies added (with \fBset-cookie\fP) in the application minus any cookies deleted (with \fBdelete-cookie\fP).
.RE
.RS 4
\[bu]
"cookie" returns the cookie value specified by <cookie index> (a sequential number starting with 1 up to the number of cookies), for instance:
.RS 4
.EX
get-req cookie-count to cookie_c
start-loop repeat cookie_c use i
get-req cookie i to cookie_val
print-format "cookie %s\en", cookie_val web-encode
@<br/>
end-loop
.EE
.RE
In this example, we get the number of cookies, and then print out each cookie value.
.RE
.RS 4
\[bu]
"arg-count" is the number of input arguments to your application (passed from a program caller, see "-a" option in \fBmgrg\fP and "--arg" in \fBgg\fP).
.RE
.RS 4
\[bu]
"arg-value" is the string value of a single element from the array of input arguments, specified by <arg_index>. This array is indexed from 1 to the value obtained by "arg-count". Here is an example of using arg-count and arg-value:
.RS 4
.EX
get-req arg-count to ac
print-format "Total args [%ld]", ac
start-loop repeat ac use i
get-req arg-value i to av
print-format "%s\en", av
end-loop
.EE
.RE
This code will display the number of input arguments (as passed to main() function of your program, excluding the first argument which is the name of the program), and then all the arguments. If there are no arguments, then variable 'ac' would be 0.
.RE
.RS 4
\[bu]
"header" is the value of HTTP request header <header> that is set by the client. For example, if the HTTP request contains header "My-Header:30", then hval would be "30":
.RS 4
.EX
get-req header "My-Header" to hval
.EE
.RE
Note that not all HTTP request headers are set by the caller. For example, SERVER_NAME or QUERY_STRING are set by the web server, and to get such headers, use \fBget-sys\fP.
.RE
.RS 4
\[bu]
"method" is the request method. This is a number with values of GG_GET, GG_POST, GG_PUT, GG_PATCH or GG_DELETE for GET, POST, PUT, PATCH or DELETE requests, respectively. If it is not any of those commonly used ones, then the value is GG_OTHER and you can use \fBget-sys\fP with "environment" clause to obtain "REQUEST_METHOD" variable.
.RE
.RS 4
\[bu]
"content-type" is the request content type. It is a string and generally denotes the content type of a \fBrequest-body\fP, if included in the request. Common examples are "application/x-www-form-urlencoded", "multipart/form-data" or "application/json".
.RE
.RS 4
\[bu]
"referring-url" is the referring URL (i.e. the page from which this request was called, for example by clicking a link).
.RE
.RS 4
\[bu]
"directory" is the current working directory, which is by default the application home directory (see \fBdirectories\fP) and can be changed with \fBchange-dir\fP. Note that maximum length of a directory path should not exceed 1024 bytes.
.RE
.RS 4
\[bu]
"trace-file" is the full path of the trace file for this request (if enabled, see \fBtrace-run\fP).
.RE
.RS 4
\[bu]
"process-id" is the "PID" (process ID) number of the currently executing process, as a number.
.RE
.RS 4
\[bu]
"external-call" is a boolean that is true if the call to the current request handler is from an external caller, or false if called from another handler.
.RE
.RS 4
\[bu]
"source-file" is the name of the current source file (a string).
.RE
.RS 4
\[bu]
"name" is the request name as specified in the \fBrequest\fP URL.
.RE
.SH EXAMPLES
Get the name of current trace file:
.RS 4
.EX
get-req trace-file to trace_file
.EE
.RE
.SH SEE ALSO
Request information
\fBget-req\fP
See all
\fBdocumentation\fP
|