浏览代码

Set code 302 automatically if CGI reply has Location: header present

Sergey Lyubka 13 年之前
父节点
当前提交
aa90972a31
共有 2 个文件被更改,包括 8 次插入2 次删除
  1. 7 2
      mongoose.c
  2. 1 0
      test/test.pl

+ 7 - 2
mongoose.c

@@ -2974,8 +2974,13 @@ static void handle_cgi_request(struct mg_connection *conn, const char *prog) {
   parse_http_headers(&pbuf, &ri);
 
   // Make up and send the status line
-  status = get_header(&ri, "Status");
-  conn->request_info.status_code = status == NULL ? 200 : atoi(status);
+  if ((status = get_header(&ri, "Status")) != NULL) {
+    conn->request_info.status_code = atoi(status);
+  } else if (get_header(&ri, "Location") != NULL) {
+    conn->request_info.status_code = 302;
+  } else {
+    conn->request_info.status_code = 200;
+  }
   (void) mg_printf(conn, "HTTP/1.1 %d OK\r\n", conn->request_info.status_code);
 
   // Send headers

+ 1 - 0
test/test.pl

@@ -322,6 +322,7 @@ unless (scalar(@ARGV) > 0 and $ARGV[0] eq "basic_tests") {
   unlink "$root/.htpasswd";
 
   o("GET /env.cgi HTTP/1.0\n\r\n", 'HTTP/1.1 200 OK', 'GET CGI file');
+  o("GET /redirect.cgi HTTP/1.0\n\n", 'HTTP/1.1 302', 'Redirect');
   o("GET /sh.cgi HTTP/1.0\n\r\n", 'shell script CGI',
     'GET sh CGI file') unless on_windows();
   o("GET /env.cgi?var=HELLO HTTP/1.0\n\n", 'QUERY_STRING=var=HELLO',