问题1:
如果您的脚本返回有效的HTTP返回码(如
200),则G-WAN会构建相应的HTTP标头,除非它们已经存在(从
"HTTP/1.x 200OK"此处开始)。
因此,要强制
content-type使用脚本语言 (不支持诸如C,C ++,D和Objective-C之类的支持G-WAN API的
语言)的给定语言 , 您必须
return 1定义答复的所有HTTP标头。
支持G-WAN API的编程语言可以使用
get_env(argv, REPLY_MIME_TYPE);(如
fractal.c和其他所示),并让G-
WAN构建其余的头文件。
问题2:
环境变量
REQUEST_URI(虽然有用)不是受支持的CGI
v1规范(RFC-3875)的一部分。我已请求
REQUEST_URI在将来的版本中添加它。
G-WAN提供的脚本示例列出了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"// ----------------------------------------------------------------------------但是请注意,您可以使用以下(和更快的)Go代码访问请求和参数(如果有):
// args[1] /opt/gwan/10.10.20.80_80/#192.168.200.80/csp/hello.go// args[2] arg1=123// args[3] arg2=456for i := 1; i < len(os.Args); i++ { fmt.Printf("args[%d] %s<br>", i, os.Args[i]) }更新
我们通过电子邮件收到了此源代码:
package mainimport "fmt"import "os"func main() { p := "<h1>Hello world!</h1><p>This is dog bla</p>" fmt.Printf("%s 200 OKrn", os.Getenv("SERVER_PROTOCOL")) fmt.Print("Content-Type: text/html; charset=UTF-8rn") fmt.Print("Connection: Keep-Alivern") fmt.Printf("Content-Length: %drn",len(p)) fmt.Print("rn") fmt.Print(p) }请注意,此代码是错误的:它甚至无法编译-并且G-WAN报告以下错误:
loading.~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Error: hell.go~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# command-line-arguments0.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 body0.0.0.0_8080/#0.0.0.0/csp/hell.go:10: non-declaration statement outside function body0.0.0.0_8080/#0.0.0.0/csp/hell.go:11: non-declaration statement outside function body0.0.0.0_8080/#0.0.0.0/csp/hell.go:12: non-declaration statement outside function body0.0.0.0_8080/#0.0.0.0/csp/hell.go:13: non-declaration statement outside function body0.0.0.0_8080/#0.0.0.0/csp/hell.go:14: non-declaration statement outside function body0.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 OKrn", os.Getenv("SERVER_PROTOCOL"))10| fmt.Print("Content-Type: text/html; charset=UTF-8rn")11| fmt.Print("Connection: Keep-Alivern")To run G-WAN, you must fix the error(s) or remove this Servlet.这很可能是您没有看到程序被“更新”的原因:旧版本(如果有的话)没有被G-WAN运行时更新的错误版本所取代。
在开发(编辑脚本)时,应始终查看终端以检查新编辑的代码是否可以编译。
我建议您看一下(有效的)
hello.go示例,以了解对
main()和的预期定义(强制性)有什么要求
return pre。
当不使用返回代码时(如您的代码),G-WAN将注入默认的HTTP标头(
HTTP/0.9 200OK在您的情况下),它将绕过HTTP标头(如果有的话),结果Internet浏览器将等待直到超时因为它不知道您的回复时间。
如示例和手册中所述,要告诉G-WAN不要创建HTTP标头,您必须返回该
1-99范围内的值(
0 means closeconnection并
200-600 is reserved for HTTP return pres告诉G-WAN生成对应的HTTP标头)。



