Perfect code logic

Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>
main
Jianhui Zhao 2017-12-30 11:10:33 +08:00
parent 278f7a19dd
commit f4852fd9cc
2 changed files with 4 additions and 7 deletions

View File

@ -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);

View File

@ -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, ...);