HTTP-4000.3.4: A library for client-side HTTP

Copyright | See LICENSE file
License | BSD
Maintainer | Ganesh Sittampalam <ganesh@earth.li>
Stability | experimental
Portability | non-portable (not tested)
Safe Haskell | Safe
Language | Haskell98

Network.BufferType

Description

In order to give the user freedom in how request and response content is represented, a sufficiently abstract representation is needed of these internally. The Network.BufferType module provides this, defining the `BufferType` class and its ad-hoc representation of buffer operations via the `BufferOp` record.

This module provides definitions for the standard buffer types that the package supports, i.e., for `String` and `ByteString` (strict and lazy.)

Synopsis

- class BufferType bufType where
- data BufferOp a = BufferOp {
  - buf_hGet :: Handle -> Int -> IO a
  - buf_hGetContents :: Handle -> IO a
  - buf_hPut :: Handle -> a -> IO ()
  - buf_hGetLine :: Handle -> IO a
  - buf_empty :: a
  - buf_append :: a -> a -> a
  - buf_concat :: [a] -> a
  - buf_fromStr :: String -> a
  - buf_toStr :: a -> String
  - buf_snoc :: a -> Word8 -> a
  - buf_splitAt :: Int -> a -> (a, a)
  - buf_span :: (Char -> Bool) -> a -> (a, a)
  - buf_isLineTerm :: a -> Bool
  - buf_isEmpty :: a -> Bool
  }
- strictBufferOp :: BufferOp ByteString
- lazyBufferOp :: BufferOp ByteString
- stringBufferOp :: BufferOp String

# Documentation

class BufferType bufType where #

The `BufferType` class encodes, in a mixed-mode way, the interface that the library requires to operate over data embedded in HTTP requests and responses. That is, we use explicit dictionaries for the operations, but overload the name of the dicts themselves.

Minimal complete definition

bufferOps

Methods

bufferOps :: BufferOp bufType #

Instances

BufferType String # |
Methods bufferOps :: BufferOp String #
BufferType ByteString # |
Methods bufferOps :: BufferOp ByteString #
BufferType ByteString # |
Methods bufferOps :: BufferOp ByteString #

data BufferOp a #

`BufferOp` encodes the I/O operations of the underlying buffer over a Handle in an (explicit) dictionary type. May not be needed, but gives us flexibility in explicit overriding and wrapping up of these methods.

Along with IO operations is an ad-hoc collection of functions for working with these abstract buffers, as needed by the internals of the code that processes requests and responses.

We supply three default `BufferOp` values, for `String` along with the strict and lazy versions of `ByteString`. To add others, provide `BufferOp` definitions for

Constructors

BufferOp |
Fields buf_hGet :: Handle -> Int -> IO a buf_hGetContents :: Handle -> IO a buf_hPut :: Handle -> a -> IO () buf_hGetLine :: Handle -> IO a buf_empty :: a buf_append :: a -> a -> a buf_concat :: [a] -> a buf_fromStr :: String -> a buf_toStr :: a -> String buf_snoc :: a -> Word8 -> a buf_splitAt :: Int -> a -> (a, a) buf_span :: (Char -> Bool) -> a -> (a, a) buf_isLineTerm :: a -> Bool buf_isEmpty :: a -> Bool

Instances

Eq (BufferOp a) # |
Methods (==) :: BufferOp a -> BufferOp a -> Bool # (/=) :: BufferOp a -> BufferOp a -> Bool #

strictBufferOp :: BufferOp ByteString #

`strictBufferOp` is the `BufferOp` definition over `ByteString`s, the non-lazy kind.

lazyBufferOp :: BufferOp ByteString #

`lazyBufferOp` is the `BufferOp` definition over `ByteString`s, the non-strict kind.

stringBufferOp :: BufferOp String #

`stringBufferOp` is the `BufferOp` definition over `String`s. It is defined in terms of `strictBufferOp` operations, unpacking/converting to `String` when needed.