Skip to content

Commit

Permalink
Implement {proxy,wai}Request roundtrip
Browse files Browse the repository at this point in the history
Signed-off-by: Erik de Castro Lopo <[email protected]>
  • Loading branch information
olorin authored and erikd committed Aug 15, 2015
1 parent 5f885da commit e302eef
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
29 changes: 21 additions & 8 deletions Network/HTTP/Proxy/Request.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ module Network.HTTP.Proxy.Request
where

import Data.ByteString.Char8 (ByteString)

import Data.Maybe

import Network.HTTP.Types (Method)
import qualified Network.HTTP.Types as HT
import qualified Network.Wai as Wai

Expand All @@ -27,13 +29,9 @@ type Port = Int
data Request = Request
{
-- | Request method such as GET.
requestMethod :: HT.Method
requestMethod :: Method
-- | HTTP version such as 1.1.
, httpVersion :: HT.HttpVersion
-- | The upstream host name.
, requestHost :: ByteString
-- | The port number of the upstream host.
, requestPort :: Port
-- | A list of header (a pair of key and value) in an HTTP request.
, requestHeaders :: HT.RequestHeaders
-- | The part of the URL after the hostname (and optional port number) and
Expand All @@ -43,12 +41,27 @@ data Request = Request
, queryString :: HT.Query
}


proxyRequest :: Wai.Request -> Request
proxyRequest = error "proxyRequest"
proxyRequest w = Request method'
version'
headers'
path'
query'
where
method' = Wai.requestMethod w
version' = Wai.httpVersion w
headers' = Wai.requestHeaders w
path' = Wai.rawPathInfo w
query' = Wai.queryString w

waiRequest :: Request -> Wai.Request
waiRequest = error "waiRequest"
waiRequest r = Wai.defaultRequest
{ Wai.requestMethod = requestMethod r
, Wai.httpVersion = httpVersion r
, Wai.requestHeaders = requestHeaders r
, Wai.rawPathInfo = requestPath r
, Wai.queryString = queryString r
}

waiRequestHost :: Wai.Request -> ByteString
waiRequestHost req = fromMaybe "???" $ Wai.requestHeaderHost req
3 changes: 3 additions & 0 deletions http-proxy.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Library
, mtl >= 2.1
, resourcet >= 1.1
, tls >= 1.2
, text >= 1.2
, transformers >= 0.3
, wai >= 3.0
, wai-conduit >= 3.0
Expand Down Expand Up @@ -69,8 +70,10 @@ Test-Suite testsuite
, http-conduit
, http-types
, hspec >= 2.1
, network
, random >= 1.1
, resourcet
, text
, wai
, wai-conduit
, warp
Expand Down

0 comments on commit e302eef

Please sign in to comment.