-/* $OpenBSD: http.h,v 1.4 2014/07/25 23:23:39 reyk Exp $ */
+/* $OpenBSD: http.h,v 1.5 2014/08/03 21:33:27 reyk Exp $ */
/*
* Copyright (c) 2012 - 2014 Reyk Floeter <reyk@openbsd.org>
#define query_key http_matchquery.kv_key
#define query_val http_matchquery.kv_value
- char http_host[MAXHOSTNAMELEN];
+ char *http_host;
enum httpmethod http_method;
int http_chunked;
char *http_version;
-/* $OpenBSD: server_http.c,v 1.32 2014/08/03 20:39:40 reyk Exp $ */
+/* $OpenBSD: server_http.c,v 1.33 2014/08/03 21:33:27 reyk Exp $ */
/*
* Copyright (c) 2006 - 2014 Reyk Floeter <reyk@openbsd.org>
free(desc->http_version);
desc->http_version = NULL;
}
+ if (desc->http_host != NULL) {
+ free(desc->http_host);
+ desc->http_host = NULL;
+ }
kv_purge(&desc->http_headers);
desc->http_lastheader = NULL;
}
server_response(struct httpd *httpd, struct client *clt)
{
char path[MAXPATHLEN];
+ char hostname[MAXHOSTNAMELEN];
struct http_descriptor *desc = clt->clt_desc;
struct server *srv = clt->clt_srv;
struct server_config *srv_conf = &srv->srv_conf, *location;
if (srv_conf != NULL) {
/* Use the actual server IP address */
- if (server_http_host(&clt->clt_srv_ss, desc->http_host,
- sizeof(desc->http_host)) == NULL)
+ if (server_http_host(&clt->clt_srv_ss, hostname,
+ sizeof(hostname)) == NULL)
goto fail;
} else {
/* Host header was valid and found */
- if (strlcpy(desc->http_host, host->kv_value,
- sizeof(desc->http_host)) >= sizeof(desc->http_host))
+ if (strlcpy(hostname, host->kv_value, sizeof(hostname)) >=
+ sizeof(hostname))
goto fail;
srv_conf = clt->clt_srv_conf;
}
+ if ((desc->http_host = strdup(hostname)) == NULL)
+ goto fail;
+
/* Now search for the location */
TAILQ_FOREACH(location, &srv->srv_hosts, entry) {
if ((location->flags & SRVFLAG_LOCATION) &&