Fix chunked encoding.

master
Nicolas Favre-Felix 14 years ago
parent 70d2e07043
commit 3e63a076a3

@ -118,9 +118,6 @@ http_client_cleanup(struct http_client *c) {
memset(&c->verb, 0, sizeof(c->verb));
cmd_free(c->cmd);
c->cmd = NULL;
c->state = CLIENT_WAITING;
c->started_responding = 0;
}

@ -46,6 +46,10 @@ http_response_set_header(struct http_response *r, const char *k, const char *v)
r->headers[pos].s = s;
r->headers[pos].sz = sz;
if(!strcmp(k, "Transfer-Encoding") && !strcmp(v, "chunked")) {
r->chunked = 1;
}
}
void
@ -72,7 +76,7 @@ http_response_write(struct http_response *r, int fd) {
char content_length[10];
sprintf(content_length, "%zd", r->body_len);
http_response_set_header(r, "Content-Length", content_length);
} else {
} else if(!r->chunked) {
http_response_set_header(r, "Content-Length", "0");
}

@ -17,6 +17,8 @@ struct http_response {
const char *body;
size_t body_len;
int chunked;
};
void
@ -32,4 +34,5 @@ http_response_set_body(struct http_response *r, const char *body, size_t body_le
int
http_response_write(struct http_response *r, int fd);
#endif

Loading…
Cancel
Save