diff --git a/source/handy_httpd/components/parse_utils.d b/source/handy_httpd/components/parse_utils.d index 48dedd2..6272dcb 100644 --- a/source/handy_httpd/components/parse_utils.d +++ b/source/handy_httpd/components/parse_utils.d @@ -190,7 +190,7 @@ public Optional!HttpRequestContext receiveRequest(InputStream, OutputStream)( ctx.request.remoteAddress = clientSocket.remoteAddress; ctx.response.outputStream = outputStreamObjectFor(outputStream); - ctx.response.headers["Connection"] = "close"; + ctx.response.addHeader("Connection", "close"); foreach (header, value; server.config.defaultHeaders) { ctx.response.addHeader(header, value); } diff --git a/source/handy_httpd/components/response.d b/source/handy_httpd/components/response.d index b6d443e..22525bc 100644 --- a/source/handy_httpd/components/response.d +++ b/source/handy_httpd/components/response.d @@ -3,6 +3,8 @@ */ module handy_httpd.components.response; +import handy_httpd.components.multivalue_map; + import std.array : appender; import std.conv : to; import std.socket : Socket; @@ -19,9 +21,9 @@ struct HttpResponse { public StatusInfo status = HttpStatus.OK; /** - * An associative array of headers. + * A multi-valued map of response headers. */ - public string[string] headers; + public StringMultiValueMap headers; /** * Internal flag used to determine if we've already flushed the headers. @@ -60,7 +62,7 @@ struct HttpResponse { if (flushed) { warnF!"Attempted to set header \"%s\" to \"%s\" after the response has already been flushed."(name, value); } - this.headers[name] = value; + this.headers.add(name, value); return this; } @@ -76,7 +78,7 @@ struct HttpResponse { warn("Attempted to set response body as chunked-encoded after headers have been flushed."); return this; } - this.headers["Transfer-Encoding"] = "chunked"; + this.addHeader("Transfer-Encoding", "chunked"); this.outputStream = outputStreamObjectFor(ChunkedEncodingOutputStream!(OutputStream!ubyte)(this.outputStream)); return this; } diff --git a/source/handy_httpd/util/builders.d b/source/handy_httpd/util/builders.d index 8d9fe75..7310635 100644 --- a/source/handy_httpd/util/builders.d +++ b/source/handy_httpd/util/builders.d @@ -286,7 +286,7 @@ class HttpResponseBuilder { private HttpRequestContextBuilder ctxBuilder; private StatusInfo status = HttpStatus.OK; - private string[string] headers; + private StringMultiValueMap headers; private OutputStream!ubyte outputStream = new ResponseCachingOutputStream(); this() {} @@ -301,13 +301,13 @@ class HttpResponseBuilder { } HttpResponseBuilder withHeader(string name, string value) { - this.headers[name] = value; + this.headers.add(name, value); return this; } HttpResponseBuilder withHeader(V)(string name, V value) { import std.conv : to; - this.headers[name] = value.to!string; + this.headers.add(name, value.to!string); return this; }