module Network.HTTP.Proxy.Request
( Port
, Request (..)
, proxyRequest
, waiRequest
, waiRequestHost
)
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
type Port = Int
data Request = Request
{
requestMethod :: Method
, httpVersion :: HT.HttpVersion
, requestHeaders :: HT.RequestHeaders
, requestPath :: ByteString
, queryString :: ByteString
} deriving (Show, Eq)
proxyRequest :: Wai.Request -> Request
proxyRequest wreq = Request
(Wai.requestMethod wreq)
(Wai.httpVersion wreq)
(Wai.requestHeaders wreq)
(Wai.rawPathInfo wreq)
(Wai.rawQueryString wreq)
waiRequest :: Wai.Request -> Request -> Wai.Request
waiRequest original req = original
{ Wai.requestMethod = requestMethod req
, Wai.httpVersion = httpVersion req
, Wai.requestHeaders = requestHeaders req
, Wai.rawPathInfo = requestPath req
, Wai.rawQueryString = queryString req
}
waiRequestHost :: Wai.Request -> ByteString
waiRequestHost req = fromMaybe "???" $ Wai.requestHeaderHost req