diff --git a/dub.json b/dub.json index 8b976fe..dc0a359 100644 --- a/dub.json +++ b/dub.json @@ -4,9 +4,9 @@ ], "copyright": "Copyright © 2024, Andrew Lalis", "dependencies": { - "handy-http-primitives": "~>1", - "photon": "~>0.10.2", - "streams": "~>3" + "handy-http-primitives": "~>1.2", + "photon": "~>0.10", + "streams": "~>3.5" }, "description": "Implementations of HTTP transport protocols.", "license": "CC0", diff --git a/source/handy_http_transport/response_output_stream.d b/source/handy_http_transport/response_output_stream.d index 9278e97..ac302e4 100644 --- a/source/handy_http_transport/response_output_stream.d +++ b/source/handy_http_transport/response_output_stream.d @@ -100,3 +100,25 @@ struct HttpResponseOutputStream(S) if (isByteOutputStream!S) { return StreamResult(cast(uint) writeCount); } } + +// Test basic functionality for writing a standard response with headers and a +// body. +unittest { + import handy_http_primitives.response; + + ArrayOutputStream!ubyte os; + ServerHttpResponse resp; + resp.status = HttpStatus.OK; + resp.headers.add("Content-Type", "text/plain"); + auto httpOut = HttpResponseOutputStream!(ArrayOutputStream!ubyte*)(&os, &resp); + resp.outputStream = outputStreamObjectFor(httpOut); + StreamResult r = resp.outputStream.writeToStream(cast(ubyte[]) "Hello world!"); + const expectedOutput = + "HTTP/1.1 200 OK\r\n" ~ + "Content-Type: text/plain\r\n" ~ + "\r\n" ~ + "Hello world!"; + assert(os.toArray() == expectedOutput); + assert(r.hasCount); + assert(r.count == os.toArray().length); +}