Skip to content

Commit

Permalink
waiProxy: don't strip Content-Length in response for HTTP/2
Browse files Browse the repository at this point in the history
HTTP/2 (and newer HTTP/3) don't use chunked encoding so it's fine to
keep Content-Length header in responses.
  • Loading branch information
bjin committed Dec 8, 2023
1 parent a8b9749 commit ffa76f7
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Network/HTTP/ReverseProxy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,12 @@ waiProxyToSettings getDest wps' manager req0 sendResponse = do
(awaitForever (\bs -> yield (Chunk $ fromByteString bs) >> yield Flush))
(wpsProcessBody wps req $ const () <$> res)
src = bodyReaderSource $ HC.responseBody res
noChunked = HT.httpMajor (WAI.httpVersion req) >= 2 || WAI.requestMethod req == HT.methodHead
sendResponse $ WAI.responseStream
(HC.responseStatus res)
(filter (\(key, _) -> not $ key `Set.member` strippedHeaders) $ HC.responseHeaders res)
(filter (\(key, v) -> not (key `Set.member` strippedHeaders) ||
key == "content-length" && (noChunked || v == "0"))
(HC.responseHeaders res))
(\sendChunk flush -> runConduit $ src .| conduit .| CL.mapM_ (\mb ->
case mb of
Flush -> flush
Expand Down

0 comments on commit ffa76f7

Please sign in to comment.