HTTP version in reply.

master
Nicolas Favre-Felix 14 years ago
parent b19fbc7680
commit 239c9004dc

@ -146,6 +146,7 @@ http_client_on_message_complete(struct http_parser *p) {
if(c->parser.http_major == 1 && c->parser.http_minor == 1) { /* 1.1 */
c->keep_alive = 1;
}
c->http_version = c->parser.http_minor;
if(p->upgrade) { /* WebSocket, don't execute just yet */
c->is_websocket = 1;

@ -31,9 +31,10 @@ struct http_client {
last_cb_t last_cb;
/* various flags. TODO: bit map */
int keep_alive;
int broken;
int is_websocket;
int keep_alive:1;
int broken:1;
int is_websocket:1;
int http_version:1;
/* HTTP data */
char *path;

@ -81,7 +81,7 @@ decode_uri(const char *uri, size_t length, size_t *out_len, int always_decode_pl
}
/* setup headers */
static void
void
cmd_setup(struct cmd *cmd, struct http_client *client) {
int i;
@ -108,6 +108,9 @@ cmd_setup(struct cmd *cmd, struct http_client *client) {
cmd->jsonp = client->jsonp;
client->jsonp = NULL;
}
cmd->fd = client->fd;
cmd->http_version = client->http_version;
}

12
cmd.h

@ -24,14 +24,15 @@ struct cmd {
/* HTTP data */
char *mime; /* forced output content-type */
int mime_free;
char *if_none_match; /* used with ETags */
char *jsonp; /* jsonp wrapper */
int keep_alive;
int keep_alive:1;
int mime_free:1; /* need to free mime buffer */
/* various flags */
int started_responding;
int is_websocket;
int started_responding:1;
int is_websocket:1;
int http_version:1;
};
struct subscription {
@ -60,4 +61,7 @@ cmd_is_subscribe(struct cmd *cmd);
void
cmd_send(redisAsyncContext *ac, formatting_fun f_format, struct cmd *cmd);
void
cmd_setup(struct cmd *cmd, struct http_client *client);
#endif

@ -51,6 +51,7 @@ format_send_reply(struct cmd *cmd, const char *p, size_t sz, const char *content
const char *ct = cmd->mime?cmd->mime:content_type;
cmd->started_responding = 1;
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_header(&resp, "Transfer-Encoding", "Chunked");
@ -73,6 +74,7 @@ format_send_reply(struct cmd *cmd, const char *p, size_t sz, const char *content
http_response_set_header(&resp, "ETag", etag);
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 {

@ -79,7 +79,7 @@ http_response_write(struct http_response *r, int fd) {
sz = sizeof("HTTP/1.x xxx ")-1 + strlen(r->msg) + 2;
s = calloc(sz + 1, 1);
ret = sprintf(s, "HTTP/1.1 %d %s\r\n", r->code, r->msg);
ret = sprintf(s, "HTTP/1.%d %d %s\r\n", (r->http_version?1:0), r->code, r->msg);
p = s;
if(r->code == 200 && r->body) {
@ -165,6 +165,7 @@ http_crossdomain(struct http_client *c) {
"</cross-domain-policy>\n";
http_response_init(&resp, 200, "OK");
resp.http_version = c->http_version;
http_response_set_connection_header(c, &resp);
http_response_set_header(&resp, "Content-Type", "application/xml");
http_response_set_body(&resp, out, sizeof(out)-1);
@ -179,6 +180,7 @@ http_send_error(struct http_client *c, short code, const char *msg) {
struct http_response resp;
http_response_init(&resp, code, msg);
resp.http_version = c->http_version;
http_response_set_connection_header(c, &resp);
http_response_set_body(&resp, NULL, 0);
@ -201,6 +203,7 @@ http_send_options(struct http_client *c) {
struct http_response resp;
http_response_init(&resp, 200, "OK");
resp.http_version = c->http_version;
http_response_set_connection_header(c, &resp);
http_response_set_header(&resp, "Content-Type", "text/html");

@ -24,7 +24,8 @@ struct http_response {
const char *body;
size_t body_len;
int chunked;
int chunked:1;
int http_version:1;
};
/* HTTP response */

@ -154,11 +154,14 @@ ws_execute(struct http_client *c, const char *frame, size_t frame_len) {
if(fun_extract) {
struct cmd *cmd = fun_extract(c, frame, frame_len);
if(cmd) {
/* copy client info into cmd. */
cmd_setup(cmd, c);
cmd->is_websocket = 1;
cmd->fd = c->fd;
/* TODO: clean this mess */
/* get redis connection from pool */
redisAsyncContext *ac = (redisAsyncContext*)pool_get_context(c->w->pool);
/* send it off */
cmd_send(ac, json_reply, cmd);
return 0;
}

Loading…
Cancel
Save