{-# LANGUAGE CPP, OverloadedStrings #-}
module Network.HTTP.Proxy.Request
( Port
, Request (..)
, proxyRequest
, waiRequest
, waiRequestHost
)
where
import Data.ByteString.Char8 (ByteString)
import Data.Maybe (fromMaybe)
import Network.HTTP.Types (Method)
import qualified Network.HTTP.Types as HT
import qualified Network.Wai as Wai
type Port = Int
data Request = Request
{
Request -> Method
requestMethod :: Method
, Request -> HttpVersion
httpVersion :: HT.HttpVersion
, :: HT.RequestHeaders
, Request -> Method
requestPath :: ByteString
, Request -> Method
queryString :: ByteString
} deriving (Int -> Request -> ShowS
[Request] -> ShowS
Request -> String
(Int -> Request -> ShowS)
-> (Request -> String) -> ([Request] -> ShowS) -> Show Request
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Request] -> ShowS
$cshowList :: [Request] -> ShowS
show :: Request -> String
$cshow :: Request -> String
showsPrec :: Int -> Request -> ShowS
$cshowsPrec :: Int -> Request -> ShowS
Show, Request -> Request -> Bool
(Request -> Request -> Bool)
-> (Request -> Request -> Bool) -> Eq Request
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Request -> Request -> Bool
$c/= :: Request -> Request -> Bool
== :: Request -> Request -> Bool
$c== :: Request -> Request -> Bool
Eq)
proxyRequest :: Wai.Request -> Request
proxyRequest :: Request -> Request
proxyRequest Request
wreq = Method
-> HttpVersion -> RequestHeaders -> Method -> Method -> Request
Request
(Request -> Method
Wai.requestMethod Request
wreq)
(Request -> HttpVersion
Wai.httpVersion Request
wreq)
(Request -> RequestHeaders
Wai.requestHeaders Request
wreq)
(Request -> Method
Wai.rawPathInfo Request
wreq)
(Request -> Method
Wai.rawQueryString Request
wreq)
waiRequest :: Wai.Request -> Request -> Wai.Request
waiRequest :: Request -> Request -> Request
waiRequest Request
original Request
req = Request
original
{ requestMethod :: Method
Wai.requestMethod = Request -> Method
requestMethod Request
req
, httpVersion :: HttpVersion
Wai.httpVersion = Request -> HttpVersion
httpVersion Request
req
, requestHeaders :: RequestHeaders
Wai.requestHeaders = Request -> RequestHeaders
requestHeaders Request
req
, rawPathInfo :: Method
Wai.rawPathInfo = Request -> Method
requestPath Request
req
, rawQueryString :: Method
Wai.rawQueryString = Request -> Method
queryString Request
req
}
waiRequestHost :: Wai.Request -> ByteString
waiRequestHost :: Request -> Method
waiRequestHost Request
req = Method -> Maybe Method -> Method
forall a. a -> Maybe a -> a
fromMaybe Method
"???" (Maybe Method -> Method) -> Maybe Method -> Method
forall a b. (a -> b) -> a -> b
$ Request -> Maybe Method
Wai.requestHeaderHost Request
req