summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels Provos <provos@gmail.com>2006-11-29 02:07:44 +0000
committerNiels Provos <provos@gmail.com>2006-11-29 02:07:44 +0000
commitfaf7e65556ca0540ef7066315ab82271c9e2081a (patch)
tree226a94bc127318b24eee567f9a2db42afec52df1
parent5a3d4ca5e2d75568d79687af5b0aa35976836e25 (diff)
downloadlibevent-faf7e65556ca0540ef7066315ab82271c9e2081a.tar.gz
merge from trunk
svn:r282
-rw-r--r--event_tagging.c5
-rw-r--r--http.c7
-rw-r--r--test/regress_http.c52
3 files changed, 62 insertions, 2 deletions
diff --git a/event_tagging.c b/event_tagging.c
index b60d722e..ac4e3475 100644
--- a/event_tagging.c
+++ b/event_tagging.c
@@ -51,11 +51,14 @@
int decode_int(u_int32_t *pnumber, struct evbuffer *evbuf);
-static struct evbuffer *_buf;
+static struct evbuffer *_buf; /* not thread safe */
void
evtag_init()
{
+ if (_buf != NULL)
+ return;
+
if ((_buf = evbuffer_new()) == NULL)
event_err(1, "%s: malloc", __func__);
}
diff --git a/http.c b/http.c
index fd5c15d2..70e05816 100644
--- a/http.c
+++ b/http.c
@@ -932,7 +932,7 @@ evhttp_read_header(int fd, short what, void *arg)
res = evhttp_parse_lines(req, evcon->input_buffer);
if (res == -1) {
/* Error while reading, terminate */
- event_warnx("%s: bad header lines on %d\n", __func__, fd);
+ event_debug(("%s: bad header lines on %d\n", __func__, fd));
evhttp_connection_fail(evcon);
return;
} else if (res == 0) {
@@ -1190,6 +1190,11 @@ evhttp_response_code(struct evhttp_request *req, int code, const char *reason)
void
evhttp_send_page(struct evhttp_request *req, struct evbuffer *databuf)
{
+ if (!req->major || !req->minor) {
+ req->major = 1;
+ req->minor = 1;
+ }
+
if (req->kind != EVHTTP_RESPONSE)
evhttp_response_code(req, 200, "OK");
diff --git a/test/regress_http.c b/test/regress_http.c
index a905b03e..219d5abd 100644
--- a/test/regress_http.c
+++ b/test/regress_http.c
@@ -416,6 +416,57 @@ http_postrequest_done(struct evhttp_request *req, void *arg)
event_loopexit(NULL);
}
+void
+http_failure_readcb(struct bufferevent *bev, void *arg)
+{
+ const char *what = "400 Bad Request";
+ if (evbuffer_find(bev->input, what, strlen(what)) != NULL) {
+ test_ok = 2;
+ event_loopexit(NULL);
+ }
+}
+
+/*
+ * Testing that the HTTP server can deal with a malformed request.
+ */
+void
+http_failure_test(void)
+{
+ struct bufferevent *bev;
+ int fd;
+ char *http_request;
+ short port = -1;
+
+ test_ok = 0;
+ fprintf(stdout, "Testing Bad HTTP Request: ");
+
+ http = http_setup(&port);
+
+ fd = http_connect("127.0.0.1", port);
+
+ /* Stupid thing to send a request */
+ bev = bufferevent_new(fd, http_failure_readcb, http_writecb,
+ http_errorcb, NULL);
+
+ http_request = "illegal request\r\n";
+
+ bufferevent_write(bev, http_request, strlen(http_request));
+
+ event_dispatch();
+
+ bufferevent_free(bev);
+ close(fd);
+
+ evhttp_free(http);
+
+ if (test_ok != 2) {
+ fprintf(stdout, "FAILED\n");
+ exit(1);
+ }
+
+ fprintf(stdout, "OK\n");
+}
+
void
http_suite(void)
@@ -423,4 +474,5 @@ http_suite(void)
http_basic_test();
http_connection_test();
http_post_test();
+ http_failure_test();
}