From f4852fd9cca5255a687b05900e364b9290d6c278 Mon Sep 17 00:00:00 2001 From: Jianhui Zhao Date: Sat, 30 Dec 2017 11:10:33 +0800 Subject: [PATCH] Perfect code logic Signed-off-by: Jianhui Zhao --- src/client.c | 9 +++------ src/client.h | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) 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, ...);