Fix ETag.

master
Nicolas Favre-Felix 14 years ago
parent 981fd54aaf
commit dac5eccde7

@ -36,7 +36,6 @@ format_send_reply(struct cmd *cmd, const char *p, size_t sz, const char *content
if(cmd_is_subscribe(cmd)) {
free_cmd = 0;
printf("wtf\n");
/* start streaming */
if(cmd->started_responding == 0) {
@ -51,15 +50,13 @@ format_send_reply(struct cmd *cmd, const char *p, size_t sz, const char *content
} else {
/* compute ETag */
char *etag = etag_new(p, sz);
const char *if_none_match;
const char *if_none_match = cmd->client->header_if_none_match.s;
/* FIXME */
#if 1
/* check If-None-Match */
if(0 /*FIXME:(if_none_match = evhttp_find_header(cmd->rq->input_headers, "If-None-Match"))
&& strcmp(if_none_match, etag) == 0*/) {
if(if_none_match && strncmp(if_none_match, etag, cmd->client->header_if_none_match.sz) == 0) {
/* SAME! send 304. */
/* evhttp_send_reply(cmd->rq, 304, "Not Modified", NULL); */
http_send_reply(cmd->client, 304, "Not Modified", NULL, 0);
} else {
http_set_header(&cmd->client->out_content_type, cmd->mime?cmd->mime:content_type);
http_set_header(&cmd->client->out_etag, etag);

@ -1,6 +1,7 @@
#include "custom-type.h"
#include "cmd.h"
#include "common.h"
#include "http.h"
#include <string.h>
#include <hiredis/hiredis.h>
@ -16,7 +17,7 @@ custom_type_reply(redisAsyncContext *c, void *r, void *privdata) {
int int_len;
if(reply == NULL) {
/* FIXME: evhttp_send_reply(cmd->rq, 404, "Not Found", NULL); */
http_send_reply(cmd->client, 404, "Not Found", NULL, 0);
return;
}
@ -39,7 +40,7 @@ custom_type_reply(redisAsyncContext *c, void *r, void *privdata) {
}
/* couldn't make sense of what the client wanted. */
/* FIXME: evhttp_send_reply(cmd->rq, 400, "Bad request", NULL); */
http_send_reply(cmd->client, 400, "Bad request", NULL, 0);
cmd_free(cmd);
}

@ -1,6 +1,7 @@
#include "raw.h"
#include "cmd.h"
#include "common.h"
#include "http.h"
#include <string.h>
#include <hiredis/hiredis.h>
@ -19,9 +20,7 @@ raw_reply(redisAsyncContext *c, void *r, void *privdata) {
(void)c;
if (reply == NULL) {
/* FIXME
evhttp_send_reply(cmd->rq, 404, "Not Found", NULL);
*/
http_send_reply(cmd->client, 404, "Not Found", NULL, 0);
return;
}

@ -96,12 +96,14 @@ http_client_reset(struct http_client *c) {
return;
}
memset(&c->path, 0, sizeof(c->path));
memset(&c->body, 0, sizeof(c->body));
memset(&c->path, 0, sizeof(str_t));
memset(&c->body, 0, sizeof(str_t));
memset(&c->header_connection, 0, sizeof(str_t));
memset(&c->header_if_none_match, 0, sizeof(str_t));
free((char*)c->out_content_type.s);
memset(&c->out_content_type, 0, sizeof(c->out_content_type));
memset(&c->out_etag, 0, sizeof(c->out_etag));
memset(&c->out_content_type, 0, sizeof(str_t));
memset(&c->out_etag, 0, sizeof(str_t));
free(c->buffer);
c->buffer = NULL;
@ -199,9 +201,11 @@ http_send_reply(struct http_client *c, short code, const char *msg,
ret = snprintf(out, sz, "HTTP/1.1 %d %s\r\n"
"Content-Type: %s\r\n"
"Content-Length: %zd\r\n"
"ETag: %s\r\n"
"Connection: %s\r\n"
"Server: Webdis\r\n"
"\r\n", code, msg, ct, body_len,
(c->out_etag.s ? c->out_etag.s : "\"\""),
(http_client_keep_alive(c) ? "Keep-Alive" : "Close")
);
@ -252,9 +256,12 @@ http_on_header_value(http_parser *p, const char *at, size_t length) {
struct http_client *c = p->data;
if(strncmp("Connection", c->last_header_name.s, length) == 0) {
if(strncmp("Connection", c->last_header_name.s, c->last_header_name.sz) == 0) {
c->header_connection.s = at;
c->header_connection.sz = length;
} else if(strncmp("If-None-Match", c->last_header_name.s, c->last_header_name.sz) == 0) {
c->header_if_none_match.s = at;
c->header_if_none_match.sz = length;
}
return 0;
}

@ -31,6 +31,7 @@ struct http_client {
str_t path;
str_t body;
str_t header_connection;
str_t header_if_none_match;
str_t out_content_type;
str_t out_etag;

Loading…
Cancel
Save