|
|
|
@ -30,10 +30,12 @@ char *etag_new(const char *p, size_t sz) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
format_send_reply(struct cmd *cmd, const char *p, size_t sz, const char *content_type) {
|
|
|
|
|
format_send_reply(struct http_client *client, const char *p, size_t sz, const char *content_type) {
|
|
|
|
|
|
|
|
|
|
int free_cmd = 1;
|
|
|
|
|
|
|
|
|
|
struct cmd *cmd = client->cmd;
|
|
|
|
|
|
|
|
|
|
if(cmd_is_subscribe(cmd)) {
|
|
|
|
|
free_cmd = 0;
|
|
|
|
|
|
|
|
|
@ -41,32 +43,32 @@ format_send_reply(struct cmd *cmd, const char *p, size_t sz, const char *content
|
|
|
|
|
if(cmd->started_responding == 0) {
|
|
|
|
|
const char *ct = cmd->mime?cmd->mime:content_type;
|
|
|
|
|
cmd->started_responding = 1;
|
|
|
|
|
http_set_header(&cmd->client->output_headers.content_type, ct, strlen(ct));
|
|
|
|
|
http_send_reply_start(cmd->client, 200, "OK");
|
|
|
|
|
http_set_header(&client->output_headers.content_type, ct, strlen(ct));
|
|
|
|
|
http_send_reply_start(client, 200, "OK");
|
|
|
|
|
}
|
|
|
|
|
http_send_reply_chunk(cmd->client, p, sz);
|
|
|
|
|
http_send_reply_chunk(client, p, sz);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
/* compute ETag */
|
|
|
|
|
char *etag = etag_new(p, sz);
|
|
|
|
|
const char *if_none_match = cmd->client->input_headers.if_none_match.s;
|
|
|
|
|
const char *if_none_match = client->input_headers.if_none_match.s;
|
|
|
|
|
|
|
|
|
|
/* check If-None-Match */
|
|
|
|
|
if(if_none_match && strncmp(if_none_match, etag, cmd->client->input_headers.if_none_match.sz) == 0) {
|
|
|
|
|
if(if_none_match && strncmp(if_none_match, etag, client->input_headers.if_none_match.sz) == 0) {
|
|
|
|
|
/* SAME! send 304. */
|
|
|
|
|
http_send_reply(cmd->client, 304, "Not Modified", NULL, 0);
|
|
|
|
|
http_send_reply(client, 304, "Not Modified", NULL, 0);
|
|
|
|
|
} else {
|
|
|
|
|
const char *ct = cmd->mime?cmd->mime:content_type;
|
|
|
|
|
http_set_header(&cmd->client->output_headers.content_type, ct, strlen(ct));
|
|
|
|
|
http_set_header(&cmd->client->output_headers.etag, etag, strlen(etag));
|
|
|
|
|
http_send_reply(cmd->client, 200, "OK", p, sz);
|
|
|
|
|
http_set_header(&client->output_headers.content_type, ct, strlen(ct));
|
|
|
|
|
http_set_header(&client->output_headers.etag, etag, strlen(etag));
|
|
|
|
|
http_send_reply(client, 200, "OK", p, sz);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free(etag);
|
|
|
|
|
}
|
|
|
|
|
/* cleanup */
|
|
|
|
|
if(free_cmd) {
|
|
|
|
|
cmd_free(cmd);
|
|
|
|
|
cmd_free(client->cmd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|