client: allow keep-alive for POST requests
[project/uhttpd.git] / client.c
index 3c1aa9daf783a587cffc9be44241de396d2d9b77..2a2393f66a2750335148849b97435410eaf40de9 100644 (file)
--- a/client.c
+++ b/client.c
@@ -194,8 +194,7 @@ static int client_parse_request(struct client *cl, char *data)
 
        req->method = h_method;
        req->version = h_version;
-       if (req->version < UH_HTTP_VER_1_1 || req->method == UH_HTTP_MSG_POST ||
-           !conf.http_keepalive)
+       if (req->version < UH_HTTP_VER_1_1 || !conf.http_keepalive)
                req->connection_close = true;
 
        return CLIENT_STATE_HEADER;
@@ -346,7 +345,7 @@ static void client_parse_header(struct client *cl, char *data)
                }
        } else if (!strcmp(data, "content-length")) {
                r->content_length = strtoul(val, &err, 0);
-               if (err && *err) {
+               if ((err && *err) || r->content_length < 0) {
                        uh_header_error(cl, 400, "Bad Request");
                        return;
                }
@@ -444,7 +443,7 @@ void client_poll_post_data(struct client *cl)
                ustream_consume(cl->us, sep + 2 - buf);
 
                /* invalid chunk length */
-               if (sep && *sep) {
+               if ((sep && *sep) || r->content_length < 0) {
                        r->content_length = 0;
                        r->transfer_chunked = 0;
                        break;
@@ -557,11 +556,13 @@ void uh_client_notify_state(struct client *cl)
                if (!s->eof || s->w.data_bytes)
                        return;
 
+#ifdef HAVE_TLS
                if (cl->tls && cl->ssl.conn && cl->ssl.conn->w.data_bytes) {
                        cl->ssl.conn->eof = s->eof;
                        if (!ustream_write_pending(cl->ssl.conn))
                                return;
                }
+#endif
        }
 
        return client_close(cl);