HttpResponse

Defines HTTP response.

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

import scala.language.implicitConversions

import scamper.http.{ BodyParser, Header, stringToEntity }
import scamper.http.ResponseStatus.Registry.Ok

val response = Ok("There is an answer.").setHeaders(
 Header("Content-Type: text/plain"),
 Header("Connection: close")
)

printf("Status Code: %d%n", response.statusCode)
printf("Reason Phrase: %s%n", response.reasonPhrase)

response.headers.foreach(println)

val contentType: Option[String] = response.getHeaderValue("Content-Type")

given BodyParser[String] = BodyParser.string()

printf("Body: %s%n", response.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

Concrete methods

def isClientError: Boolean

Tests for client error status.

Tests for client error status.

def isInformational: Boolean

Tests for informational status.

Tests for informational status.

def isRedirection: Boolean

Tests for redirection status.

Tests for redirection status.

def isServerError: Boolean

Tests for server error status.

Tests for server error status.

def isSuccessful: Boolean

Tests for successful status.

Tests for successful status.

def reasonPhrase: String

Gets reason phrase.

Gets reason phrase.

Creates response with new status.

Creates response with new status.

Returns

new response

Creates response with new HTTP version.

Creates response with new HTTP version.

Returns

new response

Gets response status.

Gets response status.

def statusCode: Int

Gets status code.

Gets status code.

Inherited methods

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

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)*): HttpResponse

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

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

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

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*): HttpResponse

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

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*): HttpResponse

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

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)*): HttpResponse

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

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): HttpResponse

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): HttpResponse

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

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): HttpResponse

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

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

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