commit c545a922a16b7565f26c1332641af67b8b18d36c
parent a3ed3bf7ebdf5da31d4627717c28fab5e94bc368
Author: Joris Vink <joris@coders.se>
Date: Thu, 30 Mar 2017 09:38:23 +0200
Preserve the full host header under req->host.
Additionally make this header available via http_request_header().
prompted by #184
Diffstat:
src/http.c | | | 50 | +++++++++++++++++++++++++++++++------------------- |
1 file changed, 31 insertions(+), 19 deletions(-)
diff --git a/src/http.c b/src/http.c
@@ -152,33 +152,15 @@ http_request_new(struct connection *c, const char *host,
const char *method, const char *path, const char *version,
struct http_request **out)
{
- char *p;
struct http_request *req;
struct kore_module_handle *hdlr;
+ char *p, *hp;
int m, flags;
size_t hostlen, pathlen, qsoff;
kore_debug("http_request_new(%p, %s, %s, %s, %s)", c, host,
method, path, version);
- switch (c->addrtype) {
- case AF_INET6:
- if (*host == '[') {
- if ((p = strrchr(host, ']')) == NULL) {
- http_error_response(c, 400);
- return (KORE_RESULT_ERROR);
- }
- p++;
- if (*p == ':')
- *p = '\0';
- }
- break;
- default:
- if ((p = strrchr(host, ':')) != NULL)
- *p = '\0';
- break;
- }
-
if ((hostlen = strlen(host)) >= KORE_DOMAINNAME_LEN - 1) {
http_error_response(c, 400);
return (KORE_RESULT_ERROR);
@@ -201,11 +183,36 @@ http_request_new(struct connection *c, const char *host,
qsoff = 0;
}
+ hp = NULL;
+
+ switch (c->addrtype) {
+ case AF_INET6:
+ if (*host == '[') {
+ if ((hp = strrchr(host, ']')) == NULL) {
+ http_error_response(c, 400);
+ return (KORE_RESULT_ERROR);
+ }
+ hp++;
+ if (*hp == ':')
+ *hp = '\0';
+ else
+ hp = NULL;
+ }
+ break;
+ default:
+ if ((hp = strrchr(host, ':')) != NULL)
+ *hp = '\0';
+ break;
+ }
+
if ((hdlr = kore_module_handler_find(host, path)) == NULL) {
http_error_response(c, 404);
return (KORE_RESULT_ERROR);
}
+ if (hp != NULL)
+ *hp = ':';
+
if (p != NULL)
*p = '?';
@@ -631,6 +638,11 @@ http_request_header(struct http_request *req, const char *header, char **out)
}
}
+ if (!strcasecmp(header, "host")) {
+ *out = req->host;
+ return (KORE_RESULT_OK);
+ }
+
return (KORE_RESULT_ERROR);
}