summaryrefslogtreecommitdiff
path: root/src/journal
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2012-11-28 18:32:01 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-01-18 01:15:54 -0500
commit8530a1436a50b3cfb6dc6231834bd04f56118d31 (patch)
tree66e977bda1165fd6ab039126291472f5ef3af1a3 /src/journal
parent9775033d260f62869d29654a27113b809a03dad9 (diff)
journal-gatewayd: allow pipelining
The request must not be answered immediately (at first call to response_handler()), but on the second. This is also important for authentication, which cannot be performed on the first call. Before: % wget -O/dev/null -S https://localhost:19531/ --2012-11-28 18:29:43-- https://localhost:19531/ Resolving localhost (localhost)... 127.0.0.1 Connecting to localhost (localhost)|127.0.0.1|:19531... connected. HTTP request sent, awaiting response... HTTP/1.1 301 Moved Permanently Connection: close Content-Length: 87 Location: /browse Content-Type: text/html Date: Wed, 28 Nov 2012 17:29:44 GMT Location: /browse [following] --2012-11-28 18:29:43-- https://localhost:19531/browse Connecting to localhost (localhost)|127.0.0.1|:19531... connected. HTTP request sent, awaiting response... HTTP/1.1 200 OK Connection: close Content-Length: 23260 Content-Type: text/html Date: Wed, 28 Nov 2012 17:29:44 GMT Length: 23260 (23K) [text/html] After: % wget --no-check-certificate -O/dev/null -S https://localhost:19531/ --2012-11-28 18:30:05-- https://localhost:19531/ Resolving localhost (localhost)... 127.0.0.1 Connecting to localhost (localhost)|127.0.0.1|:19531... connected. HTTP request sent, awaiting response... HTTP/1.1 301 Moved Permanently Content-Length: 87 Location: /browse Content-Type: text/html Date: Wed, 28 Nov 2012 17:30:05 GMT Location: /browse [following] --2012-11-28 18:30:05-- https://localhost:19531/browse Reusing existing connection to localhost:19531. HTTP request sent, awaiting response... HTTP/1.1 200 OK Content-Length: 23260 Content-Type: text/html Date: Wed, 28 Nov 2012 17:30:06 GMT Length: 23260 (23K) [text/html]
Diffstat (limited to 'src/journal')
-rw-r--r--src/journal/journal-gatewayd.c40
1 files changed, 18 insertions, 22 deletions
diff --git a/src/journal/journal-gatewayd.c b/src/journal/journal-gatewayd.c
index 613b5394a8..23939ccbca 100644
--- a/src/journal/journal-gatewayd.c
+++ b/src/journal/journal-gatewayd.c
@@ -482,18 +482,14 @@ static int request_parse_arguments(
static int request_handler_entries(
struct MHD_Connection *connection,
- void **connection_cls) {
+ void *connection_cls) {
struct MHD_Response *response;
- RequestMeta *m;
+ RequestMeta *m = connection_cls;
int r;
assert(connection);
- assert(connection_cls);
-
- m = request_meta(connection_cls);
- if (!m)
- return respond_oom(connection);
+ assert(m);
r = open_journal(m);
if (r < 0)
@@ -651,15 +647,11 @@ static int request_handler_fields(
void *connection_cls) {
struct MHD_Response *response;
- RequestMeta *m;
+ RequestMeta *m = connection_cls;
int r;
assert(connection);
- assert(connection_cls);
-
- m = request_meta(connection_cls);
- if (!m)
- return respond_oom(connection);
+ assert(m);
r = open_journal(m);
if (r < 0)
@@ -750,10 +742,10 @@ static int request_handler_file(
static int request_handler_machine(
struct MHD_Connection *connection,
- void **connection_cls) {
+ void *connection_cls) {
struct MHD_Response *response;
- RequestMeta *m;
+ RequestMeta *m = connection_cls;
int r;
_cleanup_free_ char* hostname = NULL, *os_name = NULL;
uint64_t cutoff_from, cutoff_to, usage;
@@ -762,10 +754,7 @@ static int request_handler_machine(
const char *v = "bare";
assert(connection);
-
- m = request_meta(connection_cls);
- if (!m)
- return respond_oom(connection);
+ assert(m);
r = open_journal(m);
if (r < 0)
@@ -840,26 +829,33 @@ static int request_handler(
void **connection_cls) {
assert(connection);
+ assert(connection_cls);
assert(url);
assert(method);
if (!streq(method, "GET"))
return MHD_NO;
+ if (!*connection_cls) {
+ if (!request_meta(connection_cls))
+ return respond_oom(connection);
+ return MHD_YES;
+ }
+
if (streq(url, "/"))
return request_handler_redirect(connection, "/browse");
if (streq(url, "/entries"))
- return request_handler_entries(connection, connection_cls);
+ return request_handler_entries(connection, *connection_cls);
if (startswith(url, "/fields/"))
- return request_handler_fields(connection, url + 8, connection_cls);
+ return request_handler_fields(connection, url + 8, *connection_cls);
if (streq(url, "/browse"))
return request_handler_file(connection, DOCUMENT_ROOT "/browse.html", "text/html");
if (streq(url, "/machine"))
- return request_handler_machine(connection, connection_cls);
+ return request_handler_machine(connection, *connection_cls);
return respond_error(connection, MHD_HTTP_NOT_FOUND, "Not found.\n");
}