diff --git a/src/HTTPure/Response.purs b/src/HTTPure/Response.purs index 68b4fd2..0fbc445 100644 --- a/src/HTTPure/Response.purs +++ b/src/HTTPure/Response.purs @@ -78,6 +78,7 @@ module HTTPure.Response import Prelude +import Data.String as String import Effect as Effect import Effect.Aff as Aff import Node.HTTP as HTTP @@ -104,8 +105,10 @@ type Response = send :: HTTP.Response -> Response -> Effect.Effect Unit send httpresponse { status, headers, body } = do Status.write httpresponse $ status - Headers.write httpresponse $ headers + Headers.write httpresponse $ headers <> contentLength Body.write httpresponse $ body + where + contentLength = Headers.header "Content-Length" $ show $ String.length body -- | For custom response statuses or providing a body for response codes that -- | don't typically send one. diff --git a/test/Test/HTTPure/ResponseSpec.purs b/test/Test/HTTPure/ResponseSpec.purs index 29ba0aa..a96fc6c 100644 --- a/test/Test/HTTPure/ResponseSpec.purs +++ b/test/Test/HTTPure/ResponseSpec.purs @@ -19,6 +19,12 @@ sendSpec = Spec.describe "send" do Response.send httpResponse mockResponse pure $ TestHelpers.getResponseHeader "Test" httpResponse header ?= "test" + Spec.it "sets the Content-Length header" do + header <- EffectClass.liftEffect do + httpResponse <- TestHelpers.mockResponse + Response.send httpResponse mockResponse + pure $ TestHelpers.getResponseHeader "Content-Length" httpResponse + header ?= "4" Spec.it "writes the status" do status <- EffectClass.liftEffect do httpResponse <- TestHelpers.mockResponse