parent
278f7a19dd
commit
f4852fd9cc
|
@ -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)
|
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, "%s %03i %s\r\n", http_versions[cl->request.version], code, summary);
|
||||||
cl->printf(cl, "Server: Libuhttpd %s\r\n", UHTTPD_VERSION_STRING);
|
cl->printf(cl, "Server: Libuhttpd %s\r\n", UHTTPD_VERSION_STRING);
|
||||||
|
|
||||||
if (length < 0) {
|
if (length < 0) {
|
||||||
r->chunked = true;
|
|
||||||
cl->printf(cl, "Transfer-Encoding: chunked\r\n");
|
cl->printf(cl, "Transfer-Encoding: chunked\r\n");
|
||||||
} else {
|
} else {
|
||||||
cl->printf(cl, "Content-Length: %d\r\n", length);
|
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)
|
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)
|
static void client_request_done(struct uh_client *cl)
|
||||||
{
|
{
|
||||||
struct http_request *r = &cl->request;
|
if (cl->response_length < 0)
|
||||||
|
|
||||||
if (r->chunked)
|
|
||||||
cl->printf(cl, "0\r\n\r\n");
|
cl->printf(cl, "0\r\n\r\n");
|
||||||
|
|
||||||
dispatch_done(cl);
|
dispatch_done(cl);
|
||||||
|
|
|
@ -50,7 +50,6 @@ struct http_request {
|
||||||
enum http_method method;
|
enum http_method method;
|
||||||
enum http_version version;
|
enum http_version version;
|
||||||
int content_length;
|
int content_length;
|
||||||
bool chunked;
|
|
||||||
struct kvlist hdr;
|
struct kvlist hdr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -88,6 +87,7 @@ struct uh_client {
|
||||||
struct sockaddr_in peer_addr;
|
struct sockaddr_in peer_addr;
|
||||||
struct dispatch dispatch;
|
struct dispatch dispatch;
|
||||||
bool connection_close;
|
bool connection_close;
|
||||||
|
int response_length;
|
||||||
|
|
||||||
void (*free)(struct uh_client *cl);
|
void (*free)(struct uh_client *cl);
|
||||||
void (*send_error)(struct uh_client *cl, int code, const char *summary, const char *fmt, ...);
|
void (*send_error)(struct uh_client *cl, int code, const char *summary, const char *fmt, ...);
|
||||||
|
|
Loading…
Reference in New Issue