Refactoring.

master
Nicolas Favre-Felix 14 years ago
parent a532d4abbe
commit 3035d8ee3d

@ -38,11 +38,7 @@ format_send_error(struct cmd *cmd, short code, const char *msg) {
http_response_init(&resp, code, msg);
resp.http_version = cmd->http_version;
if(cmd->keep_alive) {
http_response_set_header(&resp, "Connection", "Keep-Alive");
} else {
http_response_set_header(&resp, "Connection", "Close");
}
http_response_set_keep_alive(&resp, cmd->keep_alive);
http_response_write(&resp, cmd->fd);
cmd_free(cmd);
@ -70,7 +66,7 @@ format_send_reply(struct cmd *cmd, const char *p, size_t sz, const char *content
http_response_init(&resp, 200, "OK");
resp.http_version = cmd->http_version;
http_response_set_header(&resp, "Content-Type", ct);
http_response_set_header(&resp, "Connection", "Keep-Alive");
http_response_set_keep_alive(&resp, 1);
http_response_set_header(&resp, "Transfer-Encoding", "Chunked");
http_response_write(&resp, cmd->fd);
}
@ -92,11 +88,7 @@ format_send_reply(struct cmd *cmd, const char *p, size_t sz, const char *content
http_response_set_body(&resp, p, sz);
}
resp.http_version = cmd->http_version;
if(cmd->keep_alive) {
http_response_set_header(&resp, "Connection", "Keep-Alive");
} else {
http_response_set_header(&resp, "Connection", "Close");
}
http_response_set_keep_alive(&resp, cmd->keep_alive);
http_response_write(&resp, cmd->fd);
free(etag);
}

@ -43,11 +43,7 @@ custom_type_reply(redisAsyncContext *c, void *r, void *privdata) {
/* couldn't make sense of what the client wanted. */
http_response_init(&resp, 400, "Bad Request");
http_response_set_header(&resp, "Content-Length", "0");
if(cmd->keep_alive) {
http_response_set_header(&resp, "Connection", "Keep-Alive");
} else {
http_response_set_header(&resp, "Connection", "Close");
}
http_response_set_keep_alive(&resp, cmd->keep_alive);
http_response_write(&resp, cmd->fd);
cmd_free(cmd);
}

@ -152,6 +152,13 @@ http_response_write(struct http_response *r, int fd) {
return ret == (int)sz ? 0 : 1;
}
static void
http_response_set_connection_header(struct http_client *c, struct http_response *r) {
http_response_set_keep_alive(r, c->keep_alive);
}
/* Adobe flash cross-domain request */
void
http_crossdomain(struct http_client *c) {
@ -187,9 +194,12 @@ http_send_error(struct http_client *c, short code, const char *msg) {
http_client_reset(c);
}
/**
* Set Connection field, either Keep-Alive or Close.
*/
void
http_response_set_connection_header(struct http_client *c, struct http_response *r) {
if(c->keep_alive) {
http_response_set_keep_alive(struct http_response *r, int enabled) {
if(enabled) {
http_response_set_header(r, "Connection", "Keep-Alive");
} else {
http_response_set_header(r, "Connection", "Close");

@ -52,9 +52,9 @@ void
http_send_options(struct http_client *c);
void
http_response_set_connection_header(struct http_client *c, struct http_response *r);
http_response_write_chunk(int fd, const char *p, size_t sz);
void
http_response_write_chunk(int fd, const char *p, size_t sz);
http_response_set_keep_alive(struct http_response *r, int enabled);
#endif

Loading…
Cancel
Save