HttpRequest

Defines HTTP request.

A request is created using one of its factory methods, or you can start with a RequestMethod and build from there.

import scala.language.implicitConversions

import scamper.http.{ BodyParser, Header, stringToUri }
import scamper.http.RequestMethod.Registry.Get

val request = Get("/motd").setHeaders(
 Header("Host: localhost:8080"),
 Header("Accept: text/plain")
)

printf("Request Method: %s%n", request.method)
printf("Target URI: %s%n", request.target)

request.headers.foreach(println)

val host: Option[String] = request.getHeaderValue("Host")

given BodyParser[String] = BodyParser.string()

printf("Body: %s%n", request.as[String])
See also
Companion
object
class Object
trait Matchable
class Any

Type members

Types

Type of start line in message

Type of start line in message

Value members

Abstract methods

def path: String

Gets target path.

Gets target path.

Gets query string.

Gets query string.

def setPath(path: String): HttpRequest

Creates request with new target path.

Creates request with new target path.

Returns

new request

Creates request with new query.

Creates request with new query.

Returns

new request

Concrete methods

def isConnect: Boolean

Tests for CONNECT method.

Tests for CONNECT method.

def isDelete: Boolean

Tests for DELETE method.

Tests for DELETE method.

def isGet: Boolean

Tests for GET method.

Tests for GET method.

def isHead: Boolean

Tests for HEAD method.

Tests for HEAD method.

def isOptions: Boolean

Tests for OPTIONS method.

Tests for OPTIONS method.

def isPatch: Boolean

Tests for PATCH method.

Tests for PATCH method.

def isPost: Boolean

Tests for POST method.

Tests for POST method.

def isPut: Boolean

Tests for PUT method.

Tests for PUT method.

def isTrace: Boolean

Tests for TRACE method.

Tests for TRACE method.

Gets request method.

Gets request method.

Creates request with new method.

Creates request with new method.

Returns

new request

def setQuery(params: Map[String, Seq[String]]): HttpRequest

Creates request with new query using supplied parameters.

Creates request with new query using supplied parameters.

Returns

new request

def setQuery(params: Seq[(String, String)]): HttpRequest

Creates request with new query using supplied parameters.

Creates request with new query using supplied parameters.

Returns

new request

def setQuery(one: (String, String), more: (String, String)*): HttpRequest

Creates request with new query using supplied parameters.

Creates request with new query using supplied parameters.

Returns

new request

def setTarget(target: Uri): HttpRequest

Creates request with new target.

Creates request with new target.

Returns

new request

Creates request with new HTTP version.

Creates request with new HTTP version.

Returns

new request

def target: Uri

Gets request target.

Gets request target.

Inherited methods

def addHeaders(one: Header, more: Header*): HttpRequest

Creates message with additional headers.

Creates message with additional headers.

Value Params
more

additional message headers

one

message header

Returns

new message

Inherited from
MessageBuilder
def addHeaders(headers: Seq[Header]): HttpRequest

Creates message with additional headers.

Creates message with additional headers.

Value Params
headers

message headers

Returns

new message

Inherited from
MessageBuilder
def as[T](using parser: BodyParser[T]): T

Gets message body as instance of T.

Gets message body as instance of T.

Value Params
parser

body parser

Inherited from
HttpMessage
def attributes: Map[String, Any]

Gets message attributes.

Gets message attributes.

Note

Attributes are arbitrary values associated with message and are not part of transmitted message.

Inherited from
HttpMessage

Gets message body.

Gets message body.

Inherited from
HttpMessage
def getAttribute[T](name: String): Option[T]

Gets attribute value with given name.

Gets attribute value with given name.

Value Params
name

attribute name

Inherited from
HttpMessage
def getAttributeOrElse[T](name: String, default: => T): T

Gets attribute value with given name, or returns default if attribute not present.

Gets attribute value with given name, or returns default if attribute not present.

Value Params
default

default value

name

attribute name

Inherited from
HttpMessage
def getHeader(name: String): Option[Header]

Gets first header with given name.

Gets first header with given name.

Inherited from
HttpMessage
def getHeaderOrElse(name: String, default: => Header): Header

Gets first header with given name, or returns default if header not present.

Gets first header with given name, or returns default if header not present.

Inherited from
HttpMessage
def getHeaderValue(name: String): Option[String]

Gets first header value with given name.

Gets first header value with given name.

Inherited from
HttpMessage
def getHeaderValueOrElse(name: String, default: => String): String

Gets first header value with given name, or returns default if header not present.

Gets first header value with given name, or returns default if header not present.

Inherited from
HttpMessage
def getHeaderValues(name: String): Seq[String]

Gets header values with given name.

Gets header values with given name.

Inherited from
HttpMessage
def getHeaders(name: String): Seq[Header]

Gets headers with given name.

Gets headers with given name.

Inherited from
HttpMessage
def hasHeader(name: String): Boolean

Tests for header with given name.

Tests for header with given name.

Inherited from
HttpMessage
def headers: Seq[Header]

Gets message headers.

Gets message headers.

Inherited from
HttpMessage
def putAttributes(one: (String, Any), more: (String, Any)*): HttpRequest

Creates message with supplied attributes.

Creates message with supplied attributes.

Value Params
more

additional attribute

one

attribute

Returns

new message

Note

If attribute already exists, its value is replaced.

Inherited from
MessageBuilder
def putAttributes(attributes: Map[String, Any]): HttpRequest

Creates message with supplied attribute.

Creates message with supplied attribute.

Value Params
attributes

attributes

Returns

new message

Note

If attribute already exists, its value is replaced.

Inherited from
MessageBuilder
def putHeaders(one: Header, more: Header*): HttpRequest

Creates message with supplied headers.

Creates message with supplied headers.

Value Params
more

additional headers

one

header

Returns

new message

Note

All previous headers with same name are removed.

Inherited from
MessageBuilder
def putHeaders(headers: Seq[Header]): HttpRequest

Creates message with supplied headers.

Creates message with supplied headers.

Value Params
headers

message headers

Returns

new message

Note

All previous headers with same name are removed.

Inherited from
MessageBuilder
def removeAttributes(one: String, more: String*): HttpRequest

Creates message excluding attributes with given names.

Creates message excluding attributes with given names.

Value Params
more

additional attribute names

one

attribute name

Returns

new message

Inherited from
MessageBuilder
def removeAttributes(names: Seq[String]): HttpRequest

Creates message excluding attributes with given names.

Creates message excluding attributes with given names.

Value Params
names

attribute names

Returns

new message

Inherited from
MessageBuilder
def removeHeaders(one: String, more: String*): HttpRequest

Creates message excluding headers with given names.

Creates message excluding headers with given names.

Value Params
more

additional header names

one

header name

Returns

new message

Inherited from
MessageBuilder
def removeHeaders(names: Seq[String]): HttpRequest

Creates message excluding headers with given names.

Creates message excluding headers with given names.

Value Params
names

header names

Returns

new message

Inherited from
MessageBuilder
def setAttributes(one: (String, Any), more: (String, Any)*): HttpRequest

Creates message with supplied attributes.

Creates message with supplied attributes.

Value Params
more

additional message attributes

one

message attribute

Returns

new message

Note

All previous attributes are removed.

Inherited from
MessageBuilder
def setAttributes(attributes: Map[String, Any]): HttpRequest

Creates message with supplied attributes.

Creates message with supplied attributes.

Value Params
attributes

message attributes

Returns

new message

Note

All previous attributes are removed.

Inherited from
MessageBuilder
def setBody(body: File): HttpRequest

Creates message with supplied body.

Creates message with supplied body.

Value Params
body

message body

Returns

new message

Inherited from
MessageBuilder
def setBody(body: String): HttpRequest

Creates message with supplied body.

Creates message with supplied body.

Value Params
body

message body

Returns

new message

Inherited from
MessageBuilder
def setBody(body: Array[Byte]): HttpRequest

Creates message with supplied body.

Creates message with supplied body.

Value Params
body

message body

Returns

new message

Inherited from
MessageBuilder
def setBody(body: InputStream): HttpRequest

Creates message with supplied body.

Creates message with supplied body.

Value Params
body

message body

Returns

new message

Inherited from
MessageBuilder

Creates message with supplied body.

Creates message with supplied body.

Value Params
body

message body

Returns

new message

Inherited from
MessageBuilder
def setHeaders(one: Header, more: Header*): HttpRequest

Creates message with supplied headers.

Creates message with supplied headers.

Value Params
more

additional message headers

one

message header

Returns

new message

Note

All previous headers are removed.

Inherited from
MessageBuilder
def setHeaders(headers: Seq[Header]): HttpRequest

Creates message with supplied headers.

Creates message with supplied headers.

Value Params
headers

message headers

Returns

new message

Note

All previous headers are removed.

Inherited from
MessageBuilder

Creates message with supplied start line.

Creates message with supplied start line.

Value Params
startLine

message start line

Returns

new message

Inherited from
MessageBuilder

Gets message start line.

Gets message start line.

Inherited from
HttpMessage

Gets HTTP version.

Gets HTTP version.

Inherited from
HttpMessage