Skip to content

Commit 77a936e

Browse files
authored
Merge pull request #47 from bjin/fix-encoding
waiProxy: Remove Content-Length for Encoded Responses
2 parents 4e076eb + 4aa43a2 commit 77a936e

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11

2+
## 0.6.0.3
3+
4+
* Fix a regression introduced in 0.6.0.2: wrong 'Content-Length' header is preserved for responses with encoded content. [#47](https://github.com/fpco/http-reverse-proxy/pull/47)
5+
26
## 0.6.0.2
37

48
* Fix docker registry reverse proxying by preserving the 'Content-Length' response header to HTTP/2 and HEAD requests. [#45](https://github.com/fpco/http-reverse-proxy/pull/45)

Network/HTTP/ReverseProxy.hs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import Data.Functor.Identity (Identity (..))
5454
import Data.IORef
5555
import Data.List.NonEmpty (NonEmpty (..))
5656
import qualified Data.List.NonEmpty as NE
57-
import Data.Maybe (fromMaybe, listToMaybe)
57+
import Data.Maybe (fromMaybe, isNothing, listToMaybe)
5858
import Data.Monoid (mappend, mconcat, (<>))
5959
import Data.Set (Set)
6060
import qualified Data.Set as Set
@@ -426,12 +426,14 @@ waiProxyToSettings getDest wps' manager req0 sendResponse = do
426426
(awaitForever (\bs -> yield (Chunk $ fromByteString bs) >> yield Flush))
427427
(wpsProcessBody wps req $ const () <$> res)
428428
src = bodyReaderSource $ HC.responseBody res
429-
noChunked = HT.httpMajor (WAI.httpVersion req) >= 2 || WAI.requestMethod req == HT.methodHead
429+
headers = HC.responseHeaders res
430+
notEncoded = isNothing (lookup "content-encoding" headers)
431+
notChunked = HT.httpMajor (WAI.httpVersion req) >= 2 || WAI.requestMethod req == HT.methodHead
430432
sendResponse $ WAI.responseStream
431433
(HC.responseStatus res)
432434
(filter (\(key, v) -> not (key `Set.member` strippedHeaders) ||
433-
key == "content-length" && (noChunked || v == "0"))
434-
(HC.responseHeaders res))
435+
key == "content-length" && (notEncoded && notChunked || v == "0"))
436+
headers)
435437
(\sendChunk flush -> runConduit $ src .| conduit .| CL.mapM_ (\mb ->
436438
case mb of
437439
Flush -> flush

http-reverse-proxy.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: http-reverse-proxy
2-
version: 0.6.0.2
2+
version: 0.6.0.3
33
synopsis: Reverse proxy HTTP requests, either over raw sockets or with WAI
44
description: Provides a simple means of reverse-proxying HTTP requests. The raw approach uses the same technique as leveraged by keter, whereas the WAI approach performs full request/response parsing via WAI and http-conduit.
55
homepage: https://github.com/fpco/http-reverse-proxy

0 commit comments

Comments
 (0)