scamper.http

package scamper.http

Type members

Classlikes

Provides access to decoded message body.

Provides access to decoded message body.

Companion
object

Provides factory for BodyDecoder.

Provides factory for BodyDecoder.

Companion
class
@FunctionalInterface
trait BodyParser[T]

Provides utility for parsing message body.

Provides utility for parsing message body.

Companion
object
object BodyParser

Provides factory for BodyParser.

Provides factory for BodyParser.

Companion
class
trait Entity

Provides input stream to HTTP entity.

Provides input stream to HTTP entity.

Companion
object
object Entity

Provides factory for Entity.

Provides factory for Entity.

Companion
class
case
class EntityTooLarge(maxLength: Long) extends IOException

Indicates entity larger than established maximum length.

Indicates entity larger than established maximum length.

EntityTooLarge is a complement to ReadLimitExceeded. Whereas ReadLimitExceeded applies to raw bytes of an input stream, EntityTooLarge applies to a constructed entity, which is potentially subject to decompression.

See also
sealed
trait Header

Defines HTTP header.

Defines HTTP header.

Companion
object
object Header

Provides factory for Header.

Provides factory for Header.

Companion
class
case
class HeaderNotFound(name: String) extends HttpException

Indicates absence of specified header.

Indicates absence of specified header.

class HttpException(message: String, cause: Throwable) extends RuntimeException

Indicates exception in HTTP processing.

Indicates exception in HTTP processing.

Value Params
cause

underlying cause

message

detail message

Constructor

Constructs HttpException with supplied detail message and cause.

sealed

Defines HTTP message.

Defines HTTP message.

HttpMessage defines fundamental characteristics of an HTTP message. HttpRequest and HttpResponse extend the specification to define characteristics specific to their respective message types.

Defines HTTP request.

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

Provides factory for HttpRequest.

Provides factory for HttpRequest.

Companion
class

Defines HTTP response.

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

Provides factory for HttpResponse.

Provides factory for HttpResponse.

Companion
class
sealed

Defines HTTP version.

Defines HTTP version.

Companion
object

Provides factory for HttpVersion.

Provides factory for HttpVersion.

Companion
class

Provides builder pattern for HTTP message.

Provides builder pattern for HTTP message.

Represents query string as mapped parameters.

Represents query string as mapped parameters.

Companion
object

Provides factory for QueryString.

Provides factory for QueryString.

Companion
class
case
class ReadLimitExceeded(limit: Long) extends IOException

Indicates read of input stream exceeds established limit.

Indicates read of input stream exceeds established limit.

ReadLimitExceeded is a complement to EntityTooLarge. Whereas ReadLimitExceeded applies to raw bytes of an input stream, EntityTooLarge applies to a constructed entity, which is potentially subject to decompression.

See also
sealed
trait RequestLine extends StartLine

Defines HTTP request line.

Defines HTTP request line.

See also
Companion
object

Provides factory for RequestLine.

Provides factory for RequestLine.

Companion
class
sealed

Defines HTTP request method.

Defines HTTP request method.

See also
Companion
object

Provides factory for RequestMethod.

Provides factory for RequestMethod.

See also
Companion
class
sealed

Defines HTTP response status.

Defines HTTP response status.

See also
Companion
object

Provides factory for ResponseStatus.

Provides factory for ResponseStatus.

See also
Companion
class
sealed
trait StartLine

Defines HTTP message start line.

Defines HTTP message start line.

sealed
trait StatusLine extends StartLine

Defines HTTP status line.

Defines HTTP status line.

See also
Companion
object
object StatusLine

Provides factory for StatusLine.

Provides factory for StatusLine.

Companion
class
object Uri

Provides factory for Uri.

Provides factory for Uri.

Types

type Uri = URI

Defines alias to java.net.URI.

Defines alias to java.net.URI.

Givens

Givens

given bytesToEntity: Conversion[Array[Byte], Entity]

Converts byte array to Entity.

Converts byte array to Entity.

given fileToEntity: Conversion[File, Entity]

Converts file to Entity.

Converts file to Entity.

given inputStreamToEntity: Conversion[InputStream, Entity]

Converts input stream to Entity.

Converts input stream to Entity.

given intToResponseStatus: Conversion[Int, ResponseStatus]

Converts int to ResponseStatus.

Converts int to ResponseStatus.

given stringToEntity: Conversion[String, Entity]

Converts string to Entity.

Converts string to Entity.

given stringToHeader: Conversion[String, Header]

Converts string to Header.

Converts string to Header.

given stringToRequestMethod: Conversion[String, RequestMethod]

Converts string to RequestMethod.

Converts string to RequestMethod.

given stringToUri: Conversion[String, Uri]

Converts string to Uri.

Converts string to Uri.

given tupleToHeader: Conversion[(String, String), Header]

Converts tuple to Header where tuple is name-value pair.

Converts tuple to Header where tuple is name-value pair.

given tupleToHeaderWithDateValue: Conversion[(String, Instant), Header]

Converts tuple to Header where tuple is name-value pair.

Converts tuple to Header where tuple is name-value pair.

given tupleToHeaderWithIntValue: Conversion[(String, Int), Header]

Converts tuple to Header where tuple is name-value pair.

Converts tuple to Header where tuple is name-value pair.

given tupleToHeaderWithLongValue: Conversion[(String, Long), Header]

Converts tuple to Header where tuple is name-value pair.

Converts tuple to Header where tuple is name-value pair.

given writerToEntity: Conversion[OutputStream => Unit, Entity]

Converts writer to Entity.

Converts writer to Entity.

Extensions

Extensions

extension (headers: Seq[Header])
def getHeader(name: String): Option[Header]

Gets first header with given name.

Gets first header with given name.

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.

def getHeaderValue(name: String): Option[String]

Gets first header value with given name.

Gets first header value with given name.

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.

def getHeaderValues(name: String): Seq[String]

Gets header values with given name.

Gets header values with given name.

def getHeaders(name: String): Seq[Header]

Gets headers with given name.

Gets headers with given name.

def hasHeader(name: String): Boolean

Tests for header with given name.

Tests for header with given name.

extension [T <: HttpMessage & MessageBuilder[LazyRef(...)]](message: T)
def setFile(file: File): T

Creates new message with supplied file as message body.

Creates new message with supplied file as message body.

Content-Type is set according to file type; Content-Length is set to length of file.

Value Params
file

message body

def setForm(query: QueryString): T

Creates new message with form data from supplied query string as message body.

Creates new message with form data from supplied query string as message body.

Content-Type is set to application/x-www-form-urlencoded; Content-Length is set to length of encoded form data.

Value Params
query

message body

Note

Content-Type and Content-Length headers are set accordingly.

def setForm(data: Map[String, Seq[String]]): T

Creates new message with supplied form data as message body.

Creates new message with supplied form data as message body.

Content-Type is set to application/x-www-form-urlencoded; Content-Length is set to length of encoded form data.

Value Params
data

message body

def setForm(data: Seq[(String, String)]): T

Creates new message with supplied form data as message body.

Creates new message with supplied form data as message body.

Content-Type is set to application/x-www-form-urlencoded; Content-Length is set to length of encoded form data.

Value Params
data

message body

def setForm(data: (String, String), more: (String, String)*): T

Creates new message with supplied form data as message body.

Creates new message with supplied form data as message body.

Content-Type is set to application/x-www-form-urlencoded; Content-Length is set to length of encoded form data.

Value Params
data

form data

more

additional form data

def setOctetStream(bytes: Array[Byte]): T

Creates new message with supplied bytes as message body.

Creates new message with supplied bytes as message body.

Content-Type is set to application/octet-stream; Content-Length is set to length of bytes.

Value Params
charset

character set

text

message body

def setPlain(text: String, charset: String): T

Creates new message with supplied text as message body.

Creates new message with supplied text as message body.

Content-Type is set to text/plain with specified charset; Content-Length is set to length of encoded text.

Value Params
charset

character set

text

message body