Copyright | (c) Samuel Schlesinger 2020 |
---|---|
License | MIT |
Maintainer | sgschlesinger@gmail.com |
Stability | experimental |
Portability | POSIX, Windows |
Safe Haskell | None |
Language | Haskell2010 |
A very minimal HTTP server framework wrapping wai.
Synopsis
- newtype Server m request response = Server {
- unServer :: request -> (response -> m ResponseReceived) -> m ResponseReceived
- toApplication :: Server IO Request Response -> Application
- liftS :: Monad m => m response -> Server m request response
- serverIO :: MonadUnliftIO m => m (Server m request response -> Server IO request response)
- class Profunctor (p :: Type -> Type -> Type) where
- class Category (cat :: k -> k -> Type) where
- class MonadIO m => MonadUnliftIO (m :: Type -> Type) where
- withRunInIO :: ((forall a. m a -> IO a) -> IO b) -> m b
- data ResponseReceived
- type Application = Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived
- data Request
- requestMethod :: Request -> Method
- httpVersion :: Request -> HttpVersion
- rawPathInfo :: Request -> ByteString
- rawQueryString :: Request -> ByteString
- requestHeaders :: Request -> RequestHeaders
- isSecure :: Request -> Bool
- remoteHost :: Request -> SockAddr
- pathInfo :: Request -> [Text]
- queryString :: Request -> Query
- getRequestBodyChunk :: Request -> IO ByteString
- vault :: Request -> Vault
- requestBodyLength :: Request -> RequestBodyLength
- requestHeaderHost :: Request -> Maybe ByteString
- requestHeaderRange :: Request -> Maybe ByteString
- requestHeaderReferer :: Request -> Maybe ByteString
- requestHeaderUserAgent :: Request -> Maybe ByteString
- strictRequestBody :: Request -> IO ByteString
- lazyRequestBody :: Request -> IO ByteString
- data RequestBodyLength
- data Response
- data FilePart = FilePart {}
- responseLBS :: Status -> ResponseHeaders -> ByteString -> Response
- responseStream :: Status -> ResponseHeaders -> StreamingBody -> Response
- responseRaw :: (IO ByteString -> (ByteString -> IO ()) -> IO ()) -> Response -> Response
- responseBuilder :: Status -> ResponseHeaders -> Builder -> Response
- responseFile :: Status -> ResponseHeaders -> FilePath -> Maybe FilePart -> Response
- type StreamingBody = (Builder -> IO ()) -> IO () -> IO ()
- data Status
- mkStatus :: Int -> ByteString -> Status
- type Header = (HeaderName, ByteString)
- type HeaderName = CI ByteString
- type ResponseHeaders = [Header]
- type RequestHeaders = [Header]
- hAccept :: HeaderName
- hAcceptCharset :: HeaderName
- hAcceptEncoding :: HeaderName
- hAcceptLanguage :: HeaderName
- hAcceptRanges :: HeaderName
- hAge :: HeaderName
- hAllow :: HeaderName
- hAuthorization :: HeaderName
- hCacheControl :: HeaderName
- hConnection :: HeaderName
- hContentEncoding :: HeaderName
- hContentLanguage :: HeaderName
- hContentLocation :: HeaderName
- hContentMD5 :: HeaderName
- hContentRange :: HeaderName
- hContentType :: HeaderName
- hDate :: HeaderName
- hETag :: HeaderName
- hExpect :: HeaderName
- hExpires :: HeaderName
- hFrom :: HeaderName
- hHost :: HeaderName
- hIfMatch :: HeaderName
- hIfModifiedSince :: HeaderName
- hIfNoneMatch :: HeaderName
- hIfRange :: HeaderName
- hIfUnmodifiedSince :: HeaderName
- hLastModified :: HeaderName
- hLocation :: HeaderName
- hMaxForwards :: HeaderName
- hOrigin :: HeaderName
- hPragma :: HeaderName
- hPrefer :: HeaderName
- hPreferenceApplied :: HeaderName
- hProxyAuthenticate :: HeaderName
- hRange :: HeaderName
- hReferer :: HeaderName
- hRetryAfter :: HeaderName
- hServer :: HeaderName
- hTE :: HeaderName
- hTrailer :: HeaderName
- hTransferEncoding :: HeaderName
- hUpgrade :: HeaderName
- hUserAgent :: HeaderName
- hVary :: HeaderName
- hVia :: HeaderName
- hWWWAuthenticate :: HeaderName
- hWarning :: HeaderName
- hContentDisposition :: HeaderName
- hMIMEVersion :: HeaderName
- hCookie :: HeaderName
- hSetCookie :: HeaderName
- data ByteRange
- renderByteRangeBuilder :: ByteRange -> Builder
- renderByteRange :: ByteRange -> ByteString
- type ByteRanges = [ByteRange]
- renderByteRangesBuilder :: ByteRanges -> Builder
- parseByteRanges :: ByteString -> Maybe ByteRanges
- data HttpVersion = HttpVersion {}
- http09 :: HttpVersion
- http10 :: HttpVersion
- http11 :: HttpVersion
- http20 :: HttpVersion
- type Method = ByteString
- methodGet :: Method
- methodPost :: Method
- methodHead :: Method
- methodPut :: Method
- methodDelete :: Method
- methodTrace :: Method
- methodConnect :: Method
- methodOptions :: Method
- methodPatch :: Method
- data StdMethod
- parseMethod :: Method -> Either ByteString StdMethod
- renderMethod :: Either ByteString StdMethod -> Method
- renderStdMethod :: StdMethod -> Method
- type QueryItem = (ByteString, Maybe ByteString)
- type Query = [QueryItem]
- urlEncode :: Bool -> ByteString -> ByteString
- urlDecode :: Bool -> ByteString -> ByteString
- urlEncodeBuilder :: Bool -> ByteString -> Builder
- extractPath :: ByteString -> ByteString
- decodePath :: ByteString -> ([Text], Query)
- encodePath :: [Text] -> Query -> Builder
- data SockAddr
- type Vault = Vault RealWorld
Server Language
newtype Server m request response Source #
A server application which receives a request and responds.
Server | |
|
Instances
Functor m => Profunctor (Server m) Source # | |
Defined in Web.Porpoise | |
Monad m => Category (Server m :: Type -> Type -> Type) Source # | |
Monad (Server m request) Source # | |
Functor (Server m request) Source # | |
MonadFail m => MonadFail (Server m request) Source # | |
Defined in Web.Porpoise | |
Applicative (Server m request) Source # | |
Defined in Web.Porpoise pure :: a -> Server m request a # (<*>) :: Server m request (a -> b) -> Server m request a -> Server m request b # liftA2 :: (a -> b -> c) -> Server m request a -> Server m request b -> Server m request c # (*>) :: Server m request a -> Server m request b -> Server m request b # (<*) :: Server m request a -> Server m request b -> Server m request a # | |
MonadIO m => MonadIO (Server m request) Source # | |
Defined in Web.Porpoise | |
MonadCont (Server m request) Source # | |
toApplication :: Server IO Request Response -> Application Source #
Compile a Server
a runnable wai application.
liftS :: Monad m => m response -> Server m request response Source #
Lift a computation from the base monad into the Server
monad. This is
provided because this library prefers to use the second to last type variable
position for the contravariant component in the Profunctor
instance,
and so we are able to write a Category
instance.
serverIO :: MonadUnliftIO m => m (Server m request response -> Server IO request response) Source #
In any monad that has an instance of MonadUnliftIO
, we can retrieve a
function allowing our Server
to operate in IO
. The resulting function is
expected to be used to transform the Server
prior to calling toApplication
.
class Profunctor (p :: Type -> Type -> Type) where #
Formally, the class Profunctor
represents a profunctor
from Hask
-> Hask
.
Intuitively it is a bifunctor where the first argument is contravariant and the second argument is covariant.
You can define a Profunctor
by either defining dimap
or by defining both
lmap
and rmap
.
If you supply dimap
, you should ensure that:
dimap
id
id
≡id
If you supply lmap
and rmap
, ensure:
lmap
id
≡id
rmap
id
≡id
If you supply both, you should also ensure:
dimap
f g ≡lmap
f.
rmap
g
These ensure by parametricity:
dimap
(f.
g) (h.
i) ≡dimap
g h.
dimap
f ilmap
(f.
g) ≡lmap
g.
lmap
frmap
(f.
g) ≡rmap
f.
rmap
g
Instances
Monad m => Profunctor (Kleisli m) | |
Defined in Data.Profunctor.Unsafe dimap :: (a -> b) -> (c -> d) -> Kleisli m b c -> Kleisli m a d # lmap :: (a -> b) -> Kleisli m b c -> Kleisli m a c # rmap :: (b -> c) -> Kleisli m a b -> Kleisli m a c # (#.) :: Coercible c b => q b c -> Kleisli m a b -> Kleisli m a c # (.#) :: Coercible b a => Kleisli m b c -> q a b -> Kleisli m a c # | |
Profunctor (Tagged :: Type -> Type -> Type) | |
Defined in Data.Profunctor.Unsafe | |
Functor m => Profunctor (Server m) Source # | |
Defined in Web.Porpoise | |
Profunctor ((->) :: Type -> Type -> Type) | |
Functor w => Profunctor (Cokleisli w) | |
Defined in Data.Profunctor.Unsafe dimap :: (a -> b) -> (c -> d) -> Cokleisli w b c -> Cokleisli w a d # lmap :: (a -> b) -> Cokleisli w b c -> Cokleisli w a c # rmap :: (b -> c) -> Cokleisli w a b -> Cokleisli w a c # (#.) :: Coercible c b => q b c -> Cokleisli w a b -> Cokleisli w a c # (.#) :: Coercible b a => Cokleisli w b c -> q a b -> Cokleisli w a c # | |
Functor f => Profunctor (Joker f :: Type -> Type -> Type) | |
Defined in Data.Profunctor.Unsafe | |
Contravariant f => Profunctor (Clown f :: Type -> Type -> Type) | |
Defined in Data.Profunctor.Unsafe | |
(Profunctor p, Profunctor q) => Profunctor (Sum p q) | |
Defined in Data.Profunctor.Unsafe | |
(Profunctor p, Profunctor q) => Profunctor (Product p q) | |
Defined in Data.Profunctor.Unsafe dimap :: (a -> b) -> (c -> d) -> Product p q b c -> Product p q a d # lmap :: (a -> b) -> Product p q b c -> Product p q a c # rmap :: (b -> c) -> Product p q a b -> Product p q a c # (#.) :: Coercible c b => q0 b c -> Product p q a b -> Product p q a c # (.#) :: Coercible b a => Product p q b c -> q0 a b -> Product p q a c # | |
(Functor f, Profunctor p) => Profunctor (Tannen f p) | |
Defined in Data.Profunctor.Unsafe dimap :: (a -> b) -> (c -> d) -> Tannen f p b c -> Tannen f p a d # lmap :: (a -> b) -> Tannen f p b c -> Tannen f p a c # rmap :: (b -> c) -> Tannen f p a b -> Tannen f p a c # (#.) :: Coercible c b => q b c -> Tannen f p a b -> Tannen f p a c # (.#) :: Coercible b a => Tannen f p b c -> q a b -> Tannen f p a c # | |
(Profunctor p, Functor f, Functor g) => Profunctor (Biff p f g) | |
Defined in Data.Profunctor.Unsafe dimap :: (a -> b) -> (c -> d) -> Biff p f g b c -> Biff p f g a d # lmap :: (a -> b) -> Biff p f g b c -> Biff p f g a c # rmap :: (b -> c) -> Biff p f g a b -> Biff p f g a c # (#.) :: Coercible c b => q b c -> Biff p f g a b -> Biff p f g a c # (.#) :: Coercible b a => Biff p f g b c -> q a b -> Biff p f g a c # |
class Category (cat :: k -> k -> Type) where #
A class for categories. Instances should satisfy the laws
f.
id
= f -- (right identity)id
.
f = f -- (left identity) f.
(g.
h) = (f.
g).
h -- (associativity)
Instances
Category (Coercion :: k -> k -> Type) | Since: base-4.7.0.0 |
Category ((:~:) :: k -> k -> Type) | Since: base-4.7.0.0 |
Category ((:~~:) :: k -> k -> Type) | Since: base-4.10.0.0 |
(Category p, Category q) => Category (Product p q :: k -> k -> Type) | |
(Applicative f, Category p) => Category (Tannen f p :: k -> k -> Type) | |
Monad m => Category (Kleisli m :: Type -> Type -> Type) | Since: base-3.0 |
(Applicative f, Monad f) => Category (WhenMissing f :: Type -> Type -> Type) | Since: containers-0.5.9 |
Defined in Data.IntMap.Internal id :: WhenMissing f a a # (.) :: WhenMissing f b c -> WhenMissing f a b -> WhenMissing f a c # | |
Monad m => Category (Server m :: Type -> Type -> Type) Source # | |
Category ((->) :: Type -> Type -> Type) | Since: base-3.0 |
Defined in Control.Category | |
(Monad f, Applicative f) => Category (WhenMatched f x :: Type -> Type -> Type) | Since: containers-0.5.9 |
Defined in Data.IntMap.Internal id :: WhenMatched f x a a # (.) :: WhenMatched f x b c -> WhenMatched f x a b -> WhenMatched f x a c # | |
(Applicative f, Monad f) => Category (WhenMissing f k :: Type -> Type -> Type) | Since: containers-0.5.9 |
Defined in Data.Map.Internal id :: WhenMissing f k a a # (.) :: WhenMissing f k b c -> WhenMissing f k a b -> WhenMissing f k a c # | |
(Monad f, Applicative f) => Category (WhenMatched f k x :: Type -> Type -> Type) | Since: containers-0.5.9 |
Defined in Data.Map.Internal id :: WhenMatched f k x a a # (.) :: WhenMatched f k x b c -> WhenMatched f k x a b -> WhenMatched f k x a c # |
class MonadIO m => MonadUnliftIO (m :: Type -> Type) where #
Monads which allow their actions to be run in IO
.
While MonadIO
allows an IO
action to be lifted into another
monad, this class captures the opposite concept: allowing you to
capture the monadic context. Note that, in order to meet the laws
given below, the intuition is that a monad must have no monadic
state, but may have monadic context. This essentially limits
MonadUnliftIO
to ReaderT
and IdentityT
transformers on top of
IO
.
Laws. For any value u
returned by askUnliftIO
, it must meet the
monad transformer laws as reformulated for MonadUnliftIO
:
unliftIO u . return = return
unliftIO u (m >>= f) = unliftIO u m >>= unliftIO u . f
Instances of MonadUnliftIO
must also satisfy the idempotency law:
askUnliftIO >>= \u -> (liftIO . unliftIO u) m = m
This law showcases two properties. First, askUnliftIO
doesn't change
the monadic context, and second, liftIO . unliftIO u
is equivalent to
id
IF called in the same monadic context as askUnliftIO
.
Since: unliftio-core-0.1.0.0
withRunInIO :: ((forall a. m a -> IO a) -> IO b) -> m b #
Convenience function for capturing the monadic context and running an IO
action with a runner function. The runner function is used to run a monadic
action m
in IO
.
Since: unliftio-core-0.1.0.0
Instances
MonadUnliftIO IO | |
Defined in Control.Monad.IO.Unlift | |
MonadUnliftIO m => MonadUnliftIO (IdentityT m) | |
Defined in Control.Monad.IO.Unlift | |
MonadUnliftIO m => MonadUnliftIO (ReaderT r m) | |
Defined in Control.Monad.IO.Unlift |
data ResponseReceived #
A special datatype to indicate that the WAI handler has received the response. This is to avoid the need for Rank2Types in the definition of Application.
It is highly advised that only WAI handlers import and use the data constructor for this data type.
Since 3.0.0
type Application = Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived #
The WAI application.
Note that, since WAI 3.0, this type is structured in continuation passing
style to allow for proper safe resource handling. This was handled in the
past via other means (e.g., ResourceT
). As a demonstration:
app :: Application app req respond = bracket_ (putStrLn "Allocating scarce resource") (putStrLn "Cleaning up") (respond $ responseLBS status200 [] "Hello World")
Observing a Request
Information on the request sent by the client. This abstracts away the details of the underlying implementation.
requestMethod :: Request -> Method #
Request method such as GET.
httpVersion :: Request -> HttpVersion #
HTTP version such as 1.1.
rawPathInfo :: Request -> ByteString #
Extra path information sent by the client. The meaning varies slightly depending on backend; in a standalone server setting, this is most likely all information after the domain name. In a CGI application, this would be the information following the path to the CGI executable itself.
Middlewares and routing tools should not modify this raw value, as it may
be used for such things as creating redirect destinations by applications.
Instead, if you are writing a middleware or routing framework, modify the
pathInfo
instead. This is the approach taken by systems like Yesod
subsites.
Note: At the time of writing this documentation, there is at least one
system (Network.Wai.UrlMap
from wai-extra
) that does not follow the
above recommendation. Therefore, it is recommended that you test the
behavior of your application when using rawPathInfo
and any form of
library that might modify the Request
.
rawQueryString :: Request -> ByteString #
If no query string was specified, this should be empty. This value will include the leading question mark. Do not modify this raw value - modify queryString instead.
requestHeaders :: Request -> RequestHeaders #
A list of headers (a pair of key and value) in an HTTP request.
Was this request made over an SSL connection?
Note that this value will not tell you if the client originally made
this request over SSL, but rather whether the current connection is SSL.
The distinction lies with reverse proxies. In many cases, the client will
connect to a load balancer over SSL, but connect to the WAI handler
without SSL. In such a case, isSecure
will be False
, but from a user
perspective, there is a secure connection.
remoteHost :: Request -> SockAddr #
The client's host information.
pathInfo :: Request -> [Text] #
Path info in individual pieces - the URL without a hostname/port and without a query string, split on forward slashes.
queryString :: Request -> Query #
Parsed query string information.
getRequestBodyChunk :: Request -> IO ByteString #
Get the next chunk of the body. Returns empty
when the
body is fully consumed.
Since: wai-3.2.2
A location for arbitrary data to be shared by applications and middleware.
requestBodyLength :: Request -> RequestBodyLength #
The size of the request body. In the case of a chunked request body, this may be unknown.
Since 1.4.0
requestHeaderHost :: Request -> Maybe ByteString #
The value of the Host header in a HTTP request.
Since 2.0.0
requestHeaderRange :: Request -> Maybe ByteString #
The value of the Range header in a HTTP request.
Since 2.0.0
requestHeaderReferer :: Request -> Maybe ByteString #
The value of the Referer header in a HTTP request.
Since 3.2.0
requestHeaderUserAgent :: Request -> Maybe ByteString #
The value of the User-Agent header in a HTTP request.
Since 3.2.0
strictRequestBody :: Request -> IO ByteString #
Get the request body as a lazy ByteString. However, do not use any lazy I/O, instead reading the entire body into memory strictly.
Since 3.0.1
lazyRequestBody :: Request -> IO ByteString #
Get the request body as a lazy ByteString. This uses lazy I/O under the surface, and therefore all typical warnings regarding lazy I/O apply.
Since 1.4.1
data RequestBodyLength #
The size of the request body. In the case of chunked bodies, the size will not be known.
Since 1.4.0
Instances
Show RequestBodyLength | |
Defined in Network.Wai.Internal showsPrec :: Int -> RequestBodyLength -> ShowS # show :: RequestBodyLength -> String # showList :: [RequestBodyLength] -> ShowS # |
Building a Response
Information on which part to be sent.
Sophisticated application handles Range (and If-Range) then
create FilePart
.
responseLBS :: Status -> ResponseHeaders -> ByteString -> Response #
Creating Response
from ByteString
. This is a wrapper for
responseBuilder
.
responseStream :: Status -> ResponseHeaders -> StreamingBody -> Response #
Creating Response
from a stream of values.
In order to allocate resources in an exception-safe manner, you can use the
bracket
pattern outside of the call to responseStream
. As a trivial
example:
app :: Application app req respond = bracket_ (putStrLn "Allocating scarce resource") (putStrLn "Cleaning up") $ respond $ responseStream status200 [] $ \write flush -> do write $ byteString "Hello\n" flush write $ byteString "World\n"
Note that in some cases you can use bracket
from inside responseStream
as well. However, placing the call on the outside allows your status value
and response headers to depend on the scarce resource.
Since 3.0.0
responseRaw :: (IO ByteString -> (ByteString -> IO ()) -> IO ()) -> Response -> Response #
Create a response for a raw application. This is useful for "upgrade" situations such as WebSockets, where an application requests for the server to grant it raw network access.
This function requires a backup response to be provided, for the case where the handler in question does not support such upgrading (e.g., CGI apps).
In the event that you read from the request body before returning a
responseRaw
, behavior is undefined.
Since 2.1.0
responseBuilder :: Status -> ResponseHeaders -> Builder -> Response #
Creating Response
from Builder
.
Some questions and answers about the usage of Builder
here:
Q1. Shouldn't it be at the user's discretion to use Builders internally and then create a stream of ByteStrings?
A1. That would be less efficient, as we wouldn't get cheap concatenation with the response headers.
Q2. Isn't it really inefficient to convert from ByteString to Builder, and then right back to ByteString?
A2. No. If the ByteStrings are small, then they will be copied into a larger buffer, which should be a performance gain overall (less system calls). If they are already large, then an insert operation is used to avoid copying.
Q3. Doesn't this prevent us from creating comet-style servers, since data will be cached?
A3. You can force a Builder to output a ByteString before it is an optimal size by sending a flush command.
responseFile :: Status -> ResponseHeaders -> FilePath -> Maybe FilePart -> Response #
Creating Response
from a file.
type StreamingBody = (Builder -> IO ()) -> IO () -> IO () #
Represents a streaming HTTP response body. It's a function of two parameters; the first parameter provides a means of sending another chunk of data, and the second parameter provides a means of flushing the data to the client.
Since 3.0.0
Miscellaneous re-exports
HTTP Status.
Only the statusCode
is used for comparisons.
Please use mkStatus
to create status codes from code and message, or the Enum
instance or the
status code constants (like ok200
). There might be additional record members in the future.
Note that the Show instance is only for debugging.
mkStatus :: Int -> ByteString -> Status #
Create a Status from status code and message.
type Header = (HeaderName, ByteString) #
Header
type HeaderName = CI ByteString #
Header name
type ResponseHeaders = [Header] #
Response Headers
type RequestHeaders = [Header] #
Request Headers
hAccept :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hAcceptCharset :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hAcceptEncoding :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hAcceptLanguage :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hAge :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hAllow :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hAuthorization :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hContentEncoding :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hContentLanguage :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hContentLocation :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hDate :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hETag :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hExpect :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hExpires :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hFrom :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hHost :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hIfMatch :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hIfModifiedSince :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hIfRange :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hIfUnmodifiedSince :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hLocation :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hOrigin :: HeaderName #
HTTP Header names according to https://tools.ietf.org/html/rfc6454
hPragma :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hPrefer :: HeaderName #
HTTP Header names according to https://tools.ietf.org/html/rfc7240
hPreferenceApplied :: HeaderName #
HTTP Header names according to https://tools.ietf.org/html/rfc7240
hProxyAuthenticate :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hRange :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hReferer :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hServer :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hTE :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hTrailer :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hTransferEncoding :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hUpgrade :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hVary :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hVia :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hWWWAuthenticate :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hWarning :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hContentDisposition :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html
hCookie :: HeaderName #
HTTP Header names according to https://tools.ietf.org/html/rfc6265#section-4
HTTP Header names according to https://tools.ietf.org/html/rfc6265#section-4
RFC 2616 Byte range (individual).
Negative indices are not allowed!
Instances
Eq ByteRange | |
Data ByteRange | |
Defined in Network.HTTP.Types.Header gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> ByteRange -> c ByteRange # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c ByteRange # toConstr :: ByteRange -> Constr # dataTypeOf :: ByteRange -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c ByteRange) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ByteRange) # gmapT :: (forall b. Data b => b -> b) -> ByteRange -> ByteRange # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ByteRange -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ByteRange -> r # gmapQ :: (forall d. Data d => d -> u) -> ByteRange -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> ByteRange -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> ByteRange -> m ByteRange # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ByteRange -> m ByteRange # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ByteRange -> m ByteRange # | |
Ord ByteRange | |
Defined in Network.HTTP.Types.Header | |
Show ByteRange | |
renderByteRange :: ByteRange -> ByteString #
type ByteRanges = [ByteRange] #
RFC 2616 Byte ranges (set).
parseByteRanges :: ByteString -> Maybe ByteRanges #
Parse the value of a Range header into a ByteRanges
.
>>>
parseByteRanges "error"
Nothing>>>
parseByteRanges "bytes=0-499"
Just [ByteRangeFromTo 0 499]>>>
parseByteRanges "bytes=500-999"
Just [ByteRangeFromTo 500 999]>>>
parseByteRanges "bytes=-500"
Just [ByteRangeSuffix 500]>>>
parseByteRanges "bytes=9500-"
Just [ByteRangeFrom 9500]>>>
parseByteRanges "bytes=0-0,-1"
Just [ByteRangeFromTo 0 0,ByteRangeSuffix 1]>>>
parseByteRanges "bytes=500-600,601-999"
Just [ByteRangeFromTo 500 600,ByteRangeFromTo 601 999]>>>
parseByteRanges "bytes=500-700,601-999"
Just [ByteRangeFromTo 500 700,ByteRangeFromTo 601 999]
data HttpVersion #
HTTP Version.
Note that the Show instance is intended merely for debugging.
Instances
Eq HttpVersion | |
Defined in Network.HTTP.Types.Version (==) :: HttpVersion -> HttpVersion -> Bool # (/=) :: HttpVersion -> HttpVersion -> Bool # | |
Ord HttpVersion | |
Defined in Network.HTTP.Types.Version compare :: HttpVersion -> HttpVersion -> Ordering # (<) :: HttpVersion -> HttpVersion -> Bool # (<=) :: HttpVersion -> HttpVersion -> Bool # (>) :: HttpVersion -> HttpVersion -> Bool # (>=) :: HttpVersion -> HttpVersion -> Bool # max :: HttpVersion -> HttpVersion -> HttpVersion # min :: HttpVersion -> HttpVersion -> HttpVersion # | |
Show HttpVersion | |
Defined in Network.HTTP.Types.Version showsPrec :: Int -> HttpVersion -> ShowS # show :: HttpVersion -> String # showList :: [HttpVersion] -> ShowS # |
http09 :: HttpVersion #
HTTP 0.9
http10 :: HttpVersion #
HTTP 1.0
http11 :: HttpVersion #
HTTP 1.1
http20 :: HttpVersion #
HTTP 2.0
type Method = ByteString #
HTTP method (flat string type).
methodPost :: Method #
HTTP Method constants.
methodHead :: Method #
HTTP Method constants.
methodDelete :: Method #
HTTP Method constants.
methodTrace :: Method #
HTTP Method constants.
methodConnect :: Method #
HTTP Method constants.
methodOptions :: Method #
HTTP Method constants.
methodPatch :: Method #
HTTP Method constants.
HTTP standard method (as defined by RFC 2616, and PATCH which is defined by RFC 5789).
Instances
Bounded StdMethod | |
Enum StdMethod | |
Defined in Network.HTTP.Types.Method succ :: StdMethod -> StdMethod # pred :: StdMethod -> StdMethod # fromEnum :: StdMethod -> Int # enumFrom :: StdMethod -> [StdMethod] # enumFromThen :: StdMethod -> StdMethod -> [StdMethod] # enumFromTo :: StdMethod -> StdMethod -> [StdMethod] # enumFromThenTo :: StdMethod -> StdMethod -> StdMethod -> [StdMethod] # | |
Eq StdMethod | |
Ord StdMethod | |
Defined in Network.HTTP.Types.Method | |
Read StdMethod | |
Show StdMethod | |
Ix StdMethod | |
Defined in Network.HTTP.Types.Method range :: (StdMethod, StdMethod) -> [StdMethod] # index :: (StdMethod, StdMethod) -> StdMethod -> Int # unsafeIndex :: (StdMethod, StdMethod) -> StdMethod -> Int inRange :: (StdMethod, StdMethod) -> StdMethod -> Bool # rangeSize :: (StdMethod, StdMethod) -> Int # unsafeRangeSize :: (StdMethod, StdMethod) -> Int |
parseMethod :: Method -> Either ByteString StdMethod #
Convert a method ByteString
to a StdMethod
if possible.
renderMethod :: Either ByteString StdMethod -> Method #
Convert an algebraic method to a ByteString
.
renderStdMethod :: StdMethod -> Method #
Convert a StdMethod
to a ByteString
.
type QueryItem = (ByteString, Maybe ByteString) #
Query item
Query.
General form: a=b&c=d
, but if the value is Nothing, it becomes
a&c=d
.
:: Bool | Whether to decode |
-> ByteString | The ByteString to encode as URL |
-> ByteString | The encoded URL |
Percent-encoding for URLs.
:: Bool | Whether input is in query string. True: Query string, False: Path element |
-> ByteString | |
-> Builder |
Percent-encoding for URLs (using Builder
).
extractPath :: ByteString -> ByteString #
Extract whole path (path segments + query) from a RFC 2616 Request-URI.
>>>
extractPath "/path"
"/path"
>>>
extractPath "http://example.com:8080/path"
"/path"
>>>
extractPath "http://example.com"
"/"
>>>
extractPath ""
"/"
decodePath :: ByteString -> ([Text], Query) #
Decode a whole path (path segments + query).
encodePath :: [Text] -> Query -> Builder #
Encode a whole path (path segments + query).
Socket addresses.
The existence of a constructor does not necessarily imply that
that socket address type is supported on your system: see
isSupportedSockAddr
.
Instances
Eq SockAddr | |
Ord SockAddr | |
Defined in Network.Socket.Types | |
NFData SockAddr | |
Defined in Network.Socket.Types | |
SocketAddress SockAddr | |
Defined in Network.Socket.Types sizeOfSocketAddress :: SockAddr -> Int # peekSocketAddress :: Ptr SockAddr -> IO SockAddr # pokeSocketAddress :: Ptr a -> SockAddr -> IO () # |