diff --git a/src/client.c b/src/client.c index 7923d68..e2b4e6d 100755 --- a/src/client.c +++ b/src/client.c @@ -40,17 +40,16 @@ static inline void client_send(struct uh_client *cl, const void *data, int len) static void client_send_header(struct uh_client *cl, int code, const char *summary, int length) { - struct http_request *r = &cl->request; - cl->printf(cl, "%s %03i %s\r\n", http_versions[cl->request.version], code, summary); cl->printf(cl, "Server: Libuhttpd %s\r\n", UHTTPD_VERSION_STRING); if (length < 0) { - r->chunked = true; cl->printf(cl, "Transfer-Encoding: chunked\r\n"); } else { cl->printf(cl, "Content-Length: %d\r\n", length); } + + cl->response_length = length; } static inline void client_append_header(struct uh_client *cl, const char *name, const char *value) @@ -153,9 +152,7 @@ static inline int hdr_get_len(struct kvlist *kv, const void *data) static void client_request_done(struct uh_client *cl) { - struct http_request *r = &cl->request; - - if (r->chunked) + if (cl->response_length < 0) cl->printf(cl, "0\r\n\r\n"); dispatch_done(cl); diff --git a/src/client.h b/src/client.h index fc557f1..3d5dd26 100755 --- a/src/client.h +++ b/src/client.h @@ -50,7 +50,6 @@ struct http_request { enum http_method method; enum http_version version; int content_length; - bool chunked; struct kvlist hdr; }; @@ -88,6 +87,7 @@ struct uh_client { struct sockaddr_in peer_addr; struct dispatch dispatch; bool connection_close; + int response_length; void (*free)(struct uh_client *cl); void (*send_error)(struct uh_client *cl, int code, const char *summary, const char *fmt, ...);