HttpResponse

scamper.http.HttpResponse
See theHttpResponse companion object

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

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 isClientError: Boolean

Tests for client error status.

Tests for client error status.

Attributes

def isInformational: Boolean

Tests for informational status.

Tests for informational status.

Attributes

def isRedirection: Boolean

Tests for redirection status.

Tests for redirection status.

Attributes

def isServerError: Boolean

Tests for server error status.

Tests for server error status.

Attributes

def isSuccessful: Boolean

Tests for successful status.

Tests for successful status.

Attributes

def reasonPhrase: String

Gets reason phrase.

Gets reason phrase.

Attributes

Creates response with new status.

Creates response with new status.

Attributes

Returns

new response

Creates response with new HTTP version.

Creates response with new HTTP version.

Attributes

Returns

new response

Gets response status.

Gets response status.

Attributes

def statusCode: Int

Gets status code.

Gets status code.

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