HttpRequest

scamper.http.HttpRequest
See theHttpRequest companion object

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])

Attributes

See also
Companion
object
Graph
Supertypes
trait HttpMessage
class Object
trait Matchable
class Any

Members list

Type members

Types

Specifies start line type.

Specifies start line type.

Attributes

Value members

Concrete methods

def isConnect: Boolean

Tests for CONNECT method.

Tests for CONNECT method.

Attributes

def isDelete: Boolean

Tests for DELETE method.

Tests for DELETE method.

Attributes

def isGet: Boolean

Tests for GET method.

Tests for GET method.

Attributes

def isHead: Boolean

Tests for HEAD method.

Tests for HEAD method.

Attributes

def isOptions: Boolean

Tests for OPTIONS method.

Tests for OPTIONS method.

Attributes

def isPatch: Boolean

Tests for PATCH method.

Tests for PATCH method.

Attributes

def isPost: Boolean

Tests for POST method.

Tests for POST method.

Attributes

def isPut: Boolean

Tests for PUT method.

Tests for PUT method.

Attributes

def isTrace: Boolean

Tests for TRACE method.

Tests for TRACE method.

Attributes

Gets request method.

Gets request method.

Attributes

def path: String

Gets target path.

Gets target path.

Attributes

Gets query string.

Gets query string.

Attributes

Creates request with new method.

Creates request with new method.

Attributes

Returns

new request

def setPath(path: String): HttpRequest

Creates request with new target path.

Creates request with new target path.

Attributes

Returns

new request

Creates request with new query.

Creates request with new query.

Attributes

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.

Attributes

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.

Attributes

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.

Attributes

Returns

new request

def setTarget(target: Uri): HttpRequest

Creates request with new target.

Creates request with new target.

Attributes

Returns

new request

Creates request with new HTTP version.

Creates request with new HTTP version.

Attributes

Returns

new request

def target: Uri

Gets request target.

Gets request target.

Attributes

Inherited methods

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

Creates message with additional headers.

Creates message with additional headers.

Value parameters

more

additional message headers

one

message header

Attributes

Returns

new message

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

Creates message with additional headers.

Creates message with additional headers.

Value parameters

headers

message headers

Attributes

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 parameters

parser

body parser

Attributes

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

Gets message attributes.

Gets message attributes.

Attributes

Note

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

Inherited from:
HttpMessage
def body: Entity

Gets message body.

Gets message body.

Attributes

Inherited from:
HttpMessage
def drain(sink: OutputStream, maxLength: Long): Long

Drains decoded message body to supplied sink.

Drains decoded message body to supplied sink.

Value parameters

maxLength

maximum number of bytes

sink

sink to which message body is written

Attributes

Returns

number of bytes written

Throws
ReadLimitExceeded

if body exceeds maxLength

Inherited from:
HttpMessage
def drain(maxLength: Long): HttpMessage.this.type

Drains decoded message body.

Drains decoded message body.

Value parameters

maxLength

maximum number of bytes

Attributes

Returns

this message

Throws
ReadLimitExceeded

if body exceeds maxLength

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

Gets attribute value with given name.

Gets attribute value with given name.

Value parameters

name

attribute name

Attributes

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 parameters

default

default value

name

attribute name

Attributes

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

Gets first header with given name.

Gets first header with given name.

Attributes

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.

Attributes

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

Gets first header value with given name.

Gets first header value with given name.

Attributes

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.

Attributes

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

Gets header values with given name.

Gets header values with given name.

Attributes

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

Gets headers with given name.

Gets headers with given name.

Attributes

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

Tests for header with given name.

Tests for header with given name.

Attributes

Inherited from:
HttpMessage
def headers: Seq[Header]

Gets message headers.

Gets message headers.

Attributes

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

Creates message with supplied attributes.

Creates message with supplied attributes.

Value parameters

more

additional attribute

one

attribute

Attributes

Returns

new message

Note

If attribute already exists, its value is replaced.

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

Creates message with supplied attribute.

Creates message with supplied attribute.

Value parameters

attributes

attributes

Attributes

Returns

new message

Note

If attribute already exists, its value is replaced.

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

Creates message with supplied headers.

Creates message with supplied headers.

Value parameters

more

additional headers

one

header

Attributes

Returns

new message

Note

All previous headers with same name are removed.

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

Creates message with supplied headers.

Creates message with supplied headers.

Value parameters

headers

message headers

Attributes

Returns

new message

Note

All previous headers with same name are removed.

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

Creates message excluding attributes with given names.

Creates message excluding attributes with given names.

Value parameters

more

additional attribute names

one

attribute name

Attributes

Returns

new message

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

Creates message excluding attributes with given names.

Creates message excluding attributes with given names.

Value parameters

names

attribute names

Attributes

Returns

new message

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

Creates message excluding headers with given names.

Creates message excluding headers with given names.

Value parameters

more

additional header names

one

header name

Attributes

Returns

new message

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

Creates message excluding headers with given names.

Creates message excluding headers with given names.

Value parameters

names

header names

Attributes

Returns

new message

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

Creates message with supplied attributes.

Creates message with supplied attributes.

Value parameters

more

additional message attributes

one

message attribute

Attributes

Returns

new message

Note

All previous attributes are removed.

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

Creates message with supplied attributes.

Creates message with supplied attributes.

Value parameters

attributes

message attributes

Attributes

Returns

new message

Note

All previous attributes are removed.

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

Creates message with supplied body.

Creates message with supplied body.

Value parameters

body

message body

Attributes

Returns

new message

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

Creates message with supplied body.

Creates message with supplied body.

Value parameters

body

message body

Attributes

Returns

new message

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

Creates message with supplied body.

Creates message with supplied body.

Value parameters

body

message body

Attributes

Returns

new message

Inherited from:
MessageBuilder
def setBody(body: Entity): T

Creates message with supplied body.

Creates message with supplied body.

Value parameters

body

message body

Attributes

Returns

new message

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

Creates message with supplied headers.

Creates message with supplied headers.

Value parameters

more

additional message headers

one

message header

Attributes

Returns

new message

Note

All previous headers are removed.

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

Creates message with supplied headers.

Creates message with supplied headers.

Value parameters

headers

message headers

Attributes

Returns

new message

Note

All previous headers are removed.

Inherited from:
MessageBuilder
def setStartLine(startLine: LineType): T

Creates message with supplied start line.

Creates message with supplied start line.

Value parameters

startLine

message start line

Attributes

Returns

new message

Inherited from:
MessageBuilder

Gets message start line.

Gets message start line.

Attributes

Inherited from:
HttpMessage

Gets HTTP version.

Gets HTTP version.

Attributes

Inherited from:
HttpMessage