Question 1:
If your script returns a valid HTTP return code (e.g. 200 ), the G-WAN builds the appropriate HTTP headers if they no longer exist (starting with "HTTP/1.x 200 OK" here).
So, to force a given content-type using scripting languages ββ(except for those that support the G-WAN API, such as C, C ++, D and Objective-C), you need to return 1 and define ALL HTTP headers of your response .
Programming languages ββthat support the G-WAN API can use get_env(argv, REPLY_MIME_TYPE); (as shown in fractal.c and others), and the G-WAN will build the rest of the headers.
Question 2:
The REQUEST_URI environment variable (although useful) is not part of the supported CGI v1 specification (RFC-3875). I asked for REQUEST_URI be added in a future version.
G-WAN-supplied script examples list the supported variables on v3.12:
// ---------------------------------------------------------------------------- // CGI/1.1 environment variables: // ---------------------------------------------------------------------------- // "AUTH_TYPE", // "" | "Basic" | "Digest" | etc. // "CONTENT_LENGTH", // "" | entity_length // "CONTENT_TYPE", // "" | content_type // "GATEWAY_INTERFACE", // "CGI/1.1" // "PATH_INFO", // "" | ( "/" path ) // "PATH_TRANSLATED", // disk filename for PATH_INFO // "QUERY_STRING", // "" | ?"hellox.c&name=toto" // "REMOTE_ADDR", // client IP address // "REMOTE_HOST", // client DNS name (or IP addr) // "REMOTE_IDENT", // client identity (RFC 1413), opt // "REMOTE_USER", // client identity (if auth) // "REQUEST_METHOD", // "GET" | "HEAD" | "PUT", etc. // "SCRIPT_NAME", // "" | ("/" path "hello.c") // "SERVER_NAME", // "gwan.com" | IP address // "SERVER_PORT", // "80" // "SERVER_PROTOCOL", // "HTTP/1.1" | "HTTP/1.0" | "HTTP/0.9" // "SERVER_SOFTWARE", // "G-WAN" // ----------------------------------------------------------------------------
Please note that you can access both the request and the parameters (if any) using the following (and faster) Go code:
// args[1] /opt/gwan/10.10.20.80_80/
UPDATE
We received this source code by email:
package main import "fmt" import "os" func main() { p := "<h1>Hello world!</h1><p>This is dog bla</p>" fmt.Printf("%s 200 OK\r\n", os.Getenv("SERVER_PROTOCOL")) fmt.Print("Content-Type: text/html; charset=UTF-8\r\n") fmt.Print("Connection: Keep-Alive\r\n") fmt.Printf("Content-Length: %d\r\n",len(p)) fmt.Print("\r\n") fmt.Print(p) }
Please note that this code is incorrect: it does not even compile - and the G-WAN reports the following errors:
loading. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Error: hell.go ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # command-line-arguments 0.0.0.0_8080/#0.0.0.0/csp/hell.go:7: syntax error: unexpected semicolon or newline before { 0.0.0.0_8080/#0.0.0.0/csp/hell.go:9: non-declaration statement outside function body 0.0.0.0_8080/#0.0.0.0/csp/hell.go:10: non-declaration statement outside function body 0.0.0.0_8080/#0.0.0.0/csp/hell.go:11: non-declaration statement outside function body 0.0.0.0_8080/#0.0.0.0/csp/hell.go:12: non-declaration statement outside function body 0.0.0.0_8080/#0.0.0.0/csp/hell.go:13: non-declaration statement outside function body 0.0.0.0_8080/#0.0.0.0/csp/hell.go:14: non-declaration statement outside function body 0.0.0.0_8080/#0.0.0.0/csp/hell.go:16: syntax error: unexpected } 4|import "os" 5| 6|func main() 7!{ 8| p := "<h1>Hello world!</h1><p>This is dog bla</p>" 9| fmt.Printf("%s 200 OK\r\n", os.Getenv("SERVER_PROTOCOL")) 10| fmt.Print("Content-Type: text/html; charset=UTF-8\r\n") 11| fmt.Print("Connection: Keep-Alive\r\n") To run G-WAN, you must fix the error(s) or remove this Servlet.
Most likely, you did not notice that the program was βupdatedβ: the old version, if any, was not replaced by a faulty version, updated when G-WAN started.
When you develop (edit scripts), you should always look at the terminal to check if your recently edited code is not compiling.
I recommend that you look at the (working) hello.go to find out what requirements are needed for the expected definition of main() and (crazy) return code .
If the return code is not used (for example, in your code), G-WAN will enter the default HTTP headers ( HTTP/0.9 200 OK in your case), which will bypass your HTTP headers (if any), and as a result Internet browser, wait until it expires, because it does not know the length of your response.
As indicated in the examples and in the manual, to tell the G-WAN not to create HTTP headers, you need to return a value in the range 1-99 ( 0 means close connection and 200-600 is reserved for HTTP return codes that tell the G-WAN to generate corresponding HTTP headers).