Skip to content

Commit

Permalink
fix some problem with http server
Browse files Browse the repository at this point in the history
1). I didn't implemented persisted connection, therefore, it is not 1.1;

2). I didn't end most of the responses properly with \n
  • Loading branch information
liuliu committed Mar 7, 2014
1 parent e20a0a1 commit fad6adb
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion serve/bbf.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ int uri_bbf_detect_objects(const void* context, const void* parsed, ebb_buf* buf
data[buf->written - 1] = (i == seq->rnum - 1) ? ']' : ',';
}
char http_header[192];
snprintf(http_header, 192, ebb_http_header, buf->written);
snprintf(http_header, 192, ebb_http_header, buf->written + 1);
size_t len = strnlen(http_header, 192);
if (buf->written + len + 1 >= buf->len)
{
Expand Down
2 changes: 1 addition & 1 deletion serve/convnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ int uri_convnet_classify(const void* context, const void* parsed, ebb_buf* buf)
}
// copy the http header
char http_header[192];
snprintf(http_header, 192, ebb_http_header, buf->written);
snprintf(http_header, 192, ebb_http_header, buf->written + 1);
size_t len = strnlen(http_header, 192);
if (buf->written + len + 1 >= buf->len)
{
Expand Down
2 changes: 1 addition & 1 deletion serve/dpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ int uri_dpm_detect_objects(const void* context, const void* parsed, ebb_buf* buf
data[buf->written - 1] = (i == seq->rnum - 1) ? ']' : ',';
}
char http_header[192];
snprintf(http_header, 192, ebb_http_header, buf->written);
snprintf(http_header, 192, ebb_http_header, buf->written + 1);
size_t len = strnlen(http_header, 192);
if (buf->written + len + 1 >= buf->len)
{
Expand Down
2 changes: 1 addition & 1 deletion serve/icf.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ int uri_icf_detect_objects(const void* context, const void* parsed, ebb_buf* buf
data[buf->written - 1] = (i == seq->rnum - 1) ? ']' : ',';
}
char http_header[192];
snprintf(http_header, 192, ebb_http_header, buf->written);
snprintf(http_header, 192, ebb_http_header, buf->written + 1);
size_t len = strnlen(http_header, 192);
if (buf->written + len + 1 >= buf->len)
{
Expand Down
2 changes: 1 addition & 1 deletion serve/sift.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ int uri_sift(const void* context, const void* parsed, ebb_buf* buf)
f32 += 128;
}
char http_header[192];
snprintf(http_header, 192, ebb_http_header, buf->written);
snprintf(http_header, 192, ebb_http_header, buf->written + 1);
size_t len = strnlen(http_header, 192);
if (buf->written + len + 1 >= buf->len)
{
Expand Down
2 changes: 1 addition & 1 deletion serve/swt.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ int uri_swt_detect_words(const void* context, const void* parsed, ebb_buf* buf)
data[buf->written - 1] = (i == seq->rnum - 1) ? ']' : ',';
}
char http_header[192];
snprintf(http_header, 192, ebb_http_header, buf->written);
snprintf(http_header, 192, ebb_http_header, buf->written + 1);
size_t len = strnlen(http_header, 192);
if (buf->written + len + 1 >= buf->len)
{
Expand Down
2 changes: 1 addition & 1 deletion serve/uri.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <assert.h>
#include <stdio.h>

const char ebb_http_header[] = "HTTP/1.1 201 Created\r\nCache-Control: no-cache\r\nContent-Type: application/json; charset=utf-8\r\nContent-Length: %zd\r\n\r\n";
const char ebb_http_header[] = "HTTP/1.0 201 Created\r\nCache-Control: no-cache\r\nContent-Type: application/json; charset=utf-8\r\nContent-Length: %zd\r\n\r\n";

void uri_ebb_buf_free(ebb_buf* buf)
{
Expand Down
8 changes: 4 additions & 4 deletions serve/uri.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#include <stddef.h>

/* have to be static const char so that can use sizeof */
static const char ebb_http_404[] = "HTTP/1.1 404 Not Found\r\nCache-Control: no-cache\r\nContent-Type: application/json; charset=utf-8\r\nContent-Length: 6\r\n\r\nfalse\n";
static const char ebb_http_empty_object[] = "HTTP/1.1 201 Created\r\nCache-Control: no-cache\r\nContent-Type: application/json; charset=utf-8\r\nContent-Length: 3\r\n\r\n{}\n";
static const char ebb_http_empty_array[] = "HTTP/1.1 201 Created\r\nCache-Control: no-cache\r\nContent-Type: application/json; charset=utf-8\r\nContent-Length: 3\r\n\r\n[]\n";
static const char ebb_http_ok_true[] = "HTTP/1.1 200 OK\r\nCache-Control: no-cache\r\nContent-Type: application/json; charset=utf-8\r\nContent-Length: 5\r\n\r\ntrue\n";
static const char ebb_http_404[] = "HTTP/1.0 404 Not Found\r\nCache-Control: no-cache\r\nContent-Type: application/json; charset=utf-8\r\nContent-Length: 6\r\n\r\nfalse\n";
static const char ebb_http_empty_object[] = "HTTP/1.0 201 Created\r\nCache-Control: no-cache\r\nContent-Type: application/json; charset=utf-8\r\nContent-Length: 3\r\n\r\n{}\n";
static const char ebb_http_empty_array[] = "HTTP/1.0 201 Created\r\nCache-Control: no-cache\r\nContent-Type: application/json; charset=utf-8\r\nContent-Length: 3\r\n\r\n[]\n";
static const char ebb_http_ok_true[] = "HTTP/1.0 200 OK\r\nCache-Control: no-cache\r\nContent-Type: application/json; charset=utf-8\r\nContent-Length: 5\r\n\r\ntrue\n";
/* we should never sizeof ebb_http_header */
extern const char ebb_http_header[];

Expand Down

0 comments on commit fad6adb

Please sign in to comment.