Request

final class Request[F[_]] extends RequestPlatform[F] with Message[F] with Product with Serializable

Representation of an incoming HTTP message

A Request encapsulates the entirety of the incoming HTTP request including the status line, headers, and a possible request body.

Value Params
attributes

Immutable Map used for carrying additional information in a type safe fashion

body

fs2.Stream[F, Byte] defining the body of the request

headers

collection of Headers

httpVersion

the HTTP version

method

Method.GET, Method.POST, etc.

uri

representation of the request URI

Companion
object
trait Serializable
trait Product
trait Equals
trait Message[F]
trait Media[F]
trait RequestPlatform[F]
class Object
trait Matchable
class Any

Type members

Types

type SelfF[F0[_]] = Request[F0]

Inherited types

type Self = SelfF[F]
Inherited from
Message

Value members

Concrete methods

Add a Cookie header for the provided org.http4s.headers.Cookie

Add a Cookie header for the provided org.http4s.headers.Cookie

def addCookie(name: String, content: String): Self

Add a Cookie header with the provided values

Add a Cookie header with the provided values

def asCurl(redactHeadersWhen: CIString => Boolean): String

cURL representation of the request.

cURL representation of the request.

Supported cURL-Parameters are: -X, -H

def authType: Option[AuthScheme]
def canEqual(that: Any): Boolean

Parses all available org.http4s.headers.Cookie headers into a list of RequestCookie objects. This implementation is compatible with cookie headers formatted per HTTP/1 and HTTP/2, or even both at the same time.

Parses all available org.http4s.headers.Cookie headers into a list of RequestCookie objects. This implementation is compatible with cookie headers formatted per HTTP/1 and HTTP/2, or even both at the same time.

def decode[A](f: A => F[Response[F]])(implicit F: Monad[F], decoder: EntityDecoder[F, A]): F[Response[F]]

Helper method for decoding Requests

Helper method for decoding Requests

Attempt to decode the Request and, if successful, execute the continuation to get a Response. If decoding fails, an UnprocessableEntity Response is generated.

def decodeStrict[A](f: A => F[Response[F]])(implicit F: Monad[F], decoder: EntityDecoder[F, A]): F[Response[F]]

Helper method for decoding Requests

Helper method for decoding Requests

Attempt to decode the Request and, if successful, execute the continuation to get a Response. If decoding fails, an UnprocessableEntity Response is generated. If the decoder does not support the MediaType of the Request, a UnsupportedMediaType Response is generated instead.

def decodeWith[A](decoder: EntityDecoder[F, A], strict: Boolean)(f: A => F[Response[F]])(implicit F: Monad[F]): F[Response[F]]
def from: Option[IpAddress]

Returns the the X-Forwarded-For value if present, else the remote address.

Returns the the X-Forwarded-For value if present, else the remote address.

override def hashCode(): Int
Definition Classes
Any
def isSecure: Option[Boolean]

Whether the Request was received over a secure medium

Whether the Request was received over a secure medium

def mapK[G[_]](f: FunctionK[F, G]): Request[G]
def multiParams: Map[String, Seq[String]]

Representation of the query string as a map

Representation of the query string as a map

In case a parameter is available in query string but no value is there the sequence will be empty. If the value is empty the the sequence contains an empty string.

=====Examples=====

<table> <tr><th>Query String</th><th>Map</th></tr> <tr><td><code>?param=v</code></td><td><code>Map("param" -> Seq("v"))</code></td></tr> <tr><td><code>?param=</code></td><td><code>Map("param" -> Seq(""))</code></td></tr> <tr><td><code>?param</code></td><td><code>Map("param" -> Seq())</code></td></tr> <tr><td><code>?=value</code></td><td><code>Map("" -> Seq("value"))</code></td></tr> <tr><td><code>?p1=v1&amp;p1=v2&amp;p2=v3&amp;p2=v3</code></td><td><code>Map("p1" -> Seq("v1","v2"), "p2" -> Seq("v3","v4"))</code></td></tr> </table>

The query string is lazily parsed. If an error occurs during parsing an empty Map is returned.

def params: Map[String, String]

View of the head elements of the URI parameters in query string.

View of the head elements of the URI parameters in query string.

In case a parameter has no value the map returns an empty string.

See also

multiParams

def pathTranslated: Option[File]
def productArity: Int
def productElement(n: Int): Any
def queryString: String
def remote: Option[SocketAddress[IpAddress]]
def remoteAddr: Option[IpAddress]
def remotePort: Option[Port]
def remoteUser: Option[String]

A projection of this request without the body.

A projection of this request without the body.

def server: Option[SocketAddress[IpAddress]]
def serverAddr: Option[IpAddress]
def serverPort: Option[Port]
override def toString: String
Definition Classes
Any
def withMethod(method: Method): Self
def withUri(uri: Uri): Self

Deprecated methods

@deprecated(message = "Use {withPathInfo(Uri.Path)} instead", since = "0.22.0-M1")
def withPathInfo(pi: String): Self
Deprecated
[Since version 0.22.0-M1] Use {withPathInfo(Uri.Path)} instead

Inherited methods

def addHeader[H](h: H)(implicit evidence$1: Header[H, Recurring]): Self

Add a header to these headers. The header should be a type with a recurring Header instance to ensure that the new value can be appended to any existing values.

Add a header to these headers. The header should be a type with a recurring Header instance to ensure that the new value can be appended to any existing values.

>>> import cats.effect.IO
>>> import org.http4s.headers.Accept

>>> val req = Request[IO]().addHeader(Accept(MediaRange.`application/*`))
>>> req.headers.get[Accept]
Some(Accept(NonEmptyList(application/*)))

>>> val req2 = req.addHeader(Accept(MediaRange.`text/*`))
>>> req2.headers.get[Accept]
Some(Accept(NonEmptyList(application/*, text/*)))

////*/

Inherited from
Message
final def as[A](implicit F: MonadThrow[F], decoder: EntityDecoder[F, A]): F[A]

Decode the Media to the specified type

Decode the Media to the specified type

If no valid Status has been described, allow Ok

Type Params
A

type of the result

Value Params
decoder

EntityDecoder used to decode the Media

Returns

the effect which will generate the A

Inherited from
Media
final def attemptAs[T](implicit decoder: EntityDecoder[F, T]): DecodeResult[F, T]

Decode the Media to the specified type

Decode the Media to the specified type

Type Params
T

type of the result

Value Params
decoder

EntityDecoder used to decode the Media

Returns

the effect which will generate the DecodeResult[T]

Inherited from
Media
final def bodyText(implicit RT: RaiseThrowable[F], defaultCharset: Charset): Stream[F, String]
Inherited from
Media
final def charset: Option[Charset]
Inherited from
Media
final def contentLength: Option[Long]
Inherited from
Media
final def contentType: Option[Content-Type]
Inherited from
Media
override def covary[F2[x]]: Request[F2]

Lifts this Message's body to the specified effect type.

Lifts this Message's body to the specified effect type.

Definition Classes
Inherited from
Message
def filterHeaders(f: Raw => Boolean): Self

Keep headers that satisfy the predicate

Keep headers that satisfy the predicate

Value Params
f

predicate

Returns

a new message object which has only headers that satisfy the predicate

Inherited from
Message
def isChunked: Boolean
Inherited from
Message
def productElementName(n: Int): String
Inherited from
Product
def productElementNames: Iterator[String]
Inherited from
Product
def productIterator: Iterator[Any]
Inherited from
Product
def productPrefix: String
Inherited from
Product
def putHeaders(headers: ToRaw*): Self

Add the provided headers to the existing headers, replacing those of the same header name

Add the provided headers to the existing headers, replacing those of the same header name

>>> import cats.effect.IO
>>> import org.http4s.headers.Accept

>>> val req = Request[IO]().putHeaders(Accept(MediaRange.`application/*`))
>>> req.headers.get[Accept]
Some(Accept(NonEmptyList(application/*)))

>>> val req2 = req.putHeaders(Accept(MediaRange.`text/*`))
>>> req2.headers.get[Accept]
Some(Accept(NonEmptyList(text/*)))

////

Inherited from
Message
def remoteHost(implicit F: Sync[F]): F[Option[Hostname]]
Inherited from
RequestPlatform
def removeHeader[A](implicit h: Header[A, _]): Self
Inherited from
Message
def removeHeader(key: CIString): Self
Inherited from
Message
def trailerHeaders(implicit F: Applicative[F]): F[Headers]

The trailer headers, as specified in Section 3.6.1 of RFC 2616. The resulting F might not complete until the entire body has been consumed.

The trailer headers, as specified in Section 3.6.1 of RFC 2616. The resulting F might not complete until the entire body has been consumed.

Inherited from
Message
Inherited from
Message
def withAttribute[A](key: Key[A], value: A): Self

Generates a new message object with the specified key/value pair appended to the attributes.

Generates a new message object with the specified key/value pair appended to the attributes.

Type Params
A

type of the value to store

Value Params
key

io.chrisdavenport.vault.Key with which to associate the value

value

value associated with the key

Returns

a new message object with the key/value pair appended

Inherited from
Message
def withAttributes(attributes: Vault): Self
Inherited from
Message

Sets the entity body without affecting headers such as Transfer-Encoding or Content-Length. Most use cases are better served by withEntity, which uses an EntityEncoder to maintain the headers.

Sets the entity body without affecting headers such as Transfer-Encoding or Content-Length. Most use cases are better served by withEntity, which uses an EntityEncoder to maintain the headers.

Inherited from
Message
def withContentType(contentType: Content-Type): Self
Inherited from
Message
def withContentTypeOption(contentTypeO: Option[Content-Type]): Self
Inherited from
Message

Set an empty entity body on this message, and remove all payload headers that make no sense with an empty body.

Set an empty entity body on this message, and remove all payload headers that make no sense with an empty body.

Inherited from
Message
def withEntity[T](b: T)(implicit w: EntityEncoder[F, T]): Self

Replace the body of this message with a new body

Replace the body of this message with a new body

Type Params
T

type of the Body

Value Params
b

body to attach to this method

w

EntityEncoder with which to convert the body to an EntityBody

Returns

a new message with the new body

Inherited from
Message
def withHeaders(headers: ToRaw*): Self
Inherited from
Message
def withHeaders(headers: Headers): Self
Inherited from
Message
def withHttpVersion(httpVersion: HttpVersion): Self
Inherited from
Message
def withTrailerHeaders(trailerHeaders: F[Headers]): Self
Inherited from
Message
def withoutAttribute(key: Key[_]): Self

Returns a new message object without the specified key in the attributes.

Returns a new message object without the specified key in the attributes.

Value Params
key

io.chrisdavenport.vault.Key to remove

Returns

a new message object without the key

Inherited from
Message
Inherited from
Message

Concrete fields

val attributes: Vault
val body: EntityBody[F]
val uri: Uri