ngx-export-tools-extra 0.8.1.0 → 0.8.2.0
raw patch · 3 files changed
+43/−22 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- Changelog.md +5/−0
- NgxExport/Tools/Subrequest.hs +37/−21
- ngx-export-tools-extra.cabal +1/−1
Changelog.md view
@@ -1,3 +1,8 @@+### 0.8.2.0++- In module *NgxExport.Tools.Subrequest*, bridged HTTP subrequests return status+ code of the source end of the bridge when it returns a *non-2xx* response.+ ### 0.8.1.0 - In module *NgxExport.Tools.Subrequest*, bridged HTTP subrequests were added.
NgxExport/Tools/Subrequest.hs view
@@ -1,5 +1,5 @@ {-# LANGUAGE TemplateHaskell, OverloadedStrings, RecordWildCards #-}-{-# LANGUAGE TypeApplications, NumDecimals #-}+{-# LANGUAGE TypeApplications, TupleSections, NumDecimals #-} ----------------------------------------------------------------------------- -- |@@ -301,8 +301,9 @@ handleFullResponse :: IO L.ByteString -> IO L.ByteString handleFullResponse = handle $ \e -> do let msg = C8.pack $ show e- response500 = (500, [], "", msg)- response502 = (502, [], "", msg)+ responseXXX = (, [], "", msg)+ response500 = responseXXX 500+ response502 = responseXXX 502 return $ Binary.encode @FullResponse $ case fromException e of Just (HttpExceptionRequest _ c) ->@@ -310,6 +311,9 @@ Network.HTTP.Client.ResponseTimeout -> response502 ConnectionTimeout -> response502 ConnectionFailure _ -> response502+ StatusCodeException r _ ->+ let status = statusCode $ responseStatus r+ in responseXXX status _ -> response500 _ -> response500 @@ -889,7 +893,7 @@ -- ,\"headers\": [[\"Custom-Header\", \"$arg_a\"]] -- } -- ,\"__/sink/__\":--- {\"uri\": \"http:\/\/backend_proxy\/sink\/echo\"+-- {\"uri\": \"http:\/\/sink_proxy\/echo\" -- ,\"useUDS\": true -- } -- }\';@@ -903,13 +907,6 @@ -- } -- @ ----- ==== File /nginx.conf/: new location /\/sink/ in server /backend_proxy/--- @--- location ~ ^\/sink(.*) {--- proxy_pass http:\/\/sink$1;--- }--- @--- -- ==== File /nginx.conf/: new location /\/bridge/ in server /backend/ -- @ -- location \/bridge {@@ -920,13 +917,22 @@ -- } -- @ ----- ==== File /nginx.conf/: new server /sink/+-- ==== File /nginx.conf/: new servers /sink_proxy/ and /sink/ -- @ -- server {+-- listen unix:\/tmp\/backend.sock;+-- server_name sink_proxy;+--+-- location \/ {+-- proxy_pass http:\/\/sink;+-- }+-- }+--+-- server { -- listen 8030; -- server_name sink; ----- location \/ {+-- location \/echo { -- haskell_run_async_on_request_body reqBody $hs_rb noarg; -- add_header Bridge-Header -- \"This response was bridged from subrequest\";@@ -939,20 +945,27 @@ -- Upon receiving a request with URI /\/bridge/ at the main server, we are going -- to connect to the /source/ with the same URI at the server with port equal to -- argument /$arg_p/, and then stream its response body to a /sink/ with URI--- /\/echo/ via the proxy server /backend_proxy/. Using an internal Nginx proxy--- server for the sink end of the bridge is necessary if the sink end does not+-- /\/echo/ via proxy server /sink_proxy/. Using an internal Nginx proxy server+-- for the sink end of the bridge is necessary if the sink end does not -- recognize chunked HTTP requests! Note also that /method/ of the sink -- subrequest is always /POST/ independently of whether or not and how exactly -- it was specified. -- -- The source end puts into the bridge channel its response headers except those--- listed in 'notForwardableResponseHeaders' and all headers which names start--- with /X-Accel-/. The request headers listed in the sink configuration get--- also sent: their values override the values of the headers of the same names--- sent in the response of the source end of the bridge.+-- listed in 'notForwardableResponseHeaders' and those with names starting with+-- /X-Accel-/. The request headers listed in the sink configuration get also+-- sent: their values override the values of the headers of the same names sent+-- in the response from the source end of the bridge. --+-- Bridged HTTP subrequests have transactional semantics: any errors occurred at+-- either end of a bridge make the whole subrequest fail. Responses from the+-- source end of a bridge with /non-2xx/ status codes are regarded as a failure.+-- -- In this example, after receiving all streamed data the sink collects the--- request body in variable /$hs_rb/ and merely sends it to the client.+-- request body in variable /$hs_rb/ and merely sends it back as a response to+-- the original bridged subrequest. Then this response gets decoded with+-- handlers /fromFullResponse/ or /fromFullResponseWithException/ and finally+-- returned in the response to the client. -- -- ==== A simple test --@@ -1012,6 +1025,9 @@ then fromMaybe (throw UDSNotConfiguredError) <$> readIORef httpUDSManager else return httpManager+ -- BEWARE: a non-2xx response from the bridge source will throw+ -- StatusCodeException with this status which finally will be returned as+ -- the status code of the whole bridged subrequest reqIn <- parseUrlThrow $ srUri bridgeSource reqOut <- parseRequestF $ srUri bridgeSink withResponse (makeRequest bridgeSource reqIn) manIn $ \respIn -> do@@ -1047,7 +1063,7 @@ -- > ,"headers": [["Header1", "Value1"], ["Header2", "Value2"]] -- > } -- > ,"sink":--- > {"uri": "http://proxy/sink"+-- > {"uri": "http://sink_proxy/" -- > ,"useUDS": true -- > } -- > }
ngx-export-tools-extra.cabal view
@@ -1,5 +1,5 @@ name: ngx-export-tools-extra-version: 0.8.1.0+version: 0.8.2.0 synopsis: More extra tools for Nginx haskell module description: More extra tools for <https://github.com/lyokha/nginx-haskell-module Nginx haskell module>.