From 53a13840bddfbf8b11e4bb5704eb470d44bd63b9 Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Mon, 27 May 2024 22:49:29 +0200 Subject: [PATCH] Add `Host` header into target uri Previously this would lead to an abort for an empty path (`/`), because `http:/` cannot be parsed correctly. The URI becomes the `target` in `request`, so it seems best to add the `Host` header value too. Note that this is still not 100% correct: HTTP headers are case-insensitive, so it could also be `host:` or `HoSt`. Right now headers are not normalized. However it will not abort if `Host` is missing: In that case `header_get` returns an empty string and then `http:///` (three slashes) is parsed with an empty host name as expected. --- net/http/request.ha | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/http/request.ha b/net/http/request.ha index cb85a8c..acc56ae 100644 --- a/net/http/request.ha +++ b/net/http/request.ha @@ -149,7 +149,8 @@ export fn request_parse(file: io::handle) (request | protoerr | io::error) = { case let uri: authority => return errors::unsupported; case let uri: *uri::uri => yield uri; case let path: str => - const uri = fmt::asprintf("http:{}", path); + const host = header_get(&header, "Host"); + const uri = fmt::asprintf("http://{}{}", host, path); defer free(uri); yield alloc(uri::parse(uri)!); };