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]
static int request_handler_entries(
struct MHD_Connection *connection,
static int request_handler_entries(
struct MHD_Connection *connection,
- void **connection_cls) {
+ void *connection_cls) {
struct MHD_Response *response;
struct MHD_Response *response;
+ RequestMeta *m = connection_cls;
int r;
assert(connection);
int r;
assert(connection);
- assert(connection_cls);
-
- m = request_meta(connection_cls);
- if (!m)
- return respond_oom(connection);
r = open_journal(m);
if (r < 0)
r = open_journal(m);
if (r < 0)
void *connection_cls) {
struct MHD_Response *response;
void *connection_cls) {
struct MHD_Response *response;
+ RequestMeta *m = connection_cls;
int r;
assert(connection);
int r;
assert(connection);
- assert(connection_cls);
-
- m = request_meta(connection_cls);
- if (!m)
- return respond_oom(connection);
r = open_journal(m);
if (r < 0)
r = open_journal(m);
if (r < 0)
static int request_handler_machine(
struct MHD_Connection *connection,
static int request_handler_machine(
struct MHD_Connection *connection,
- void **connection_cls) {
+ void *connection_cls) {
struct MHD_Response *response;
struct MHD_Response *response;
+ RequestMeta *m = connection_cls;
int r;
_cleanup_free_ char* hostname = NULL, *os_name = NULL;
uint64_t cutoff_from, cutoff_to, usage;
int r;
_cleanup_free_ char* hostname = NULL, *os_name = NULL;
uint64_t cutoff_from, cutoff_to, usage;
const char *v = "bare";
assert(connection);
const char *v = "bare";
assert(connection);
-
- m = request_meta(connection_cls);
- if (!m)
- return respond_oom(connection);
r = open_journal(m);
if (r < 0)
r = open_journal(m);
if (r < 0)
void **connection_cls) {
assert(connection);
void **connection_cls) {
assert(connection);
+ assert(connection_cls);
assert(url);
assert(method);
if (!streq(method, "GET"))
return MHD_NO;
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"))
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/"))
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"))
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");
}
return respond_error(connection, MHD_HTTP_NOT_FOUND, "Not found.\n");
}