uhttpd: make Lua handler more CGI like and fork child away
[project/luci.git] / contrib / package / uhttpd / src / uhttpd-file.c
index e8ea174..2a06f85 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * uhttpd - Tiny non-forking httpd - Static file handler
+ * uhttpd - Tiny single-threaded httpd - Static file handler
  *
  *   Copyright (C) 2010 Jo-Philipp Wich <xm@subsignal.org>
  *
@@ -101,6 +101,8 @@ static char * uh_file_header_lookup(struct http_request *req, const char *name)
 
 static void uh_file_response_ok_hdrs(struct client *cl, struct http_request *req, struct stat *s)
 {
+       uh_http_sendf(cl, NULL, "Connection: close\r\n");
+
        if( s )
        {
                uh_http_sendf(cl, NULL, "ETag: %s\r\n", uh_file_mktag(s));
@@ -124,8 +126,9 @@ static void uh_file_response_304(struct client *cl, struct http_request *req, st
 
 static void uh_file_response_412(struct client *cl, struct http_request *req)
 {
-       uh_http_sendf(cl, NULL, "HTTP/%.1f 412 Precondition Failed\r\n",
-               req->version);
+       uh_http_sendf(cl, NULL,
+               "HTTP/%.1f 412 Precondition Failed\r\n"
+               "Connection: close\r\n", req->version);
 }
 
 static int uh_file_if_match(struct client *cl, struct http_request *req, struct stat *s)
@@ -349,7 +352,8 @@ void uh_file_request(struct client *cl, struct http_request *req, struct path_in
                                /* pump file data */
                                while( (rlen = read(fd, buf, sizeof(buf))) > 0 )
                                {
-                                       uh_http_send(cl, req, buf, rlen);
+                                       if( uh_http_send(cl, req, buf, rlen) < 0 )
+                                               break;
                                }
 
                                /* send trailer in chunked mode */