Response

object Response
Companion
class
class Object
trait Matchable
class Any

Type members

Classlikes

final case
class PathResponse extends Response
class PermanentCache(shouldMemoize: Request => Boolean, cachedResponse: (Request, Response) => ZIO[Any, Unit, Response], cacheKey: Request => String, requestHandler: PartialFunction[Request, IO[HTTPError, Response]]) extends PartialFunction[Request, IO[HTTPError, Response]]

A cache that memoizes responses for eligible requests, and can cache response bodies of eligible responses

A cache that memoizes responses for eligible requests, and can cache response bodies of eligible responses

Companion
object
Companion
class
final case

Value members

Concrete methods

def const(body: Array[Byte], status: Status, contentType: String, headers: List[(String, String)]): Response
def fromInputStream(stream: ZManaged[Any, Throwable, InputStream], size: Long, contentType: String, status: Status, headers: List[(String, String)]): UIO[Response]
def fromPath(path: Path, request: Request, contentType: String, status: Status, headers: List[(String, String)]): IO[Throwable, Response]

Read a response from a path. Uses blocking I/O, so that a file on the local filesystem can be directly transferred to the connection using OS-level primitives when possible.

Read a response from a path. Uses blocking I/O, so that a file on the local filesystem can be directly transferred to the connection using OS-level primitives when possible.

Note that you mustn't use this method if the response may be cached, as (depending on the request) it may produce a 304 Not Modified response. You don't want that being served to other clients! Use

Value Params
contentType

The Content-Type header to use for the response. Defaults to application/octet-stream.

headers

Any additional headers to include in the response.

path

A Path pointing to the file on the filesystem.

request

The request to respond to. This is used:

  • To check if the If-Modified-Since header value included in the request for this file. If given (in RFC 1123 format), an attempt will be made to determine if the file has been modified since the requested timestamp. If it hasn't, then the response returned will be a 304 Not Modified response with no body.
  • To provide the URI for a NotFound error, in case the path does not exist.
status

The status of the response. Defaults to Ok (HTTP 200)

Returns

A ZIO value which, when evaluated, will attempt to locate the given resource and provide an appropriate Response. If the resource isn't present, it will fail with HTTPError.NotFound. Since this response interacts with the filesystem, it can fail with other arbitrary Throwable failures; you'll probably need to catch these and convert them to HTTPError failures.

def fromResource(name: String, request: Request, classLoader: ClassLoader, contentType: String, status: Status, headers: List[(String, String)]): IO[Throwable, Response]

Read a response from a resource. Uses blocking I/O, so that a file on the local filesystem can be directly transferred to the connection using OS-level primitives when possible.

Read a response from a resource. Uses blocking I/O, so that a file on the local filesystem can be directly transferred to the connection using OS-level primitives when possible.

Value Params
classLoader

The class loader which can find the resource (defaults to this class's class loader)

contentType

The Content-Type header to use for the response. Defaults to application/octet-stream.

headers

Any additional headers to include in the response.

name

The name (path) of the resource

request

The request to respond to. This is used:

  • To check if the If-Modified-Since header value included in the request for this file. If given (in RFC 1123 format), an attempt will be made to determine if the file has been modified since the requested timestamp. If it hasn't, then the response returned will be a 304 Not Modified response with no body.
  • To provide the URI for a NotFound error, in case the path does not exist.
status

The status of the response. Defaults to Ok (HTTP 200)

Returns

A ZIO value which, when evaluated, will attempt to locate the given resource and provide an appropriate Response. If the resource isn't present, it will fail with HTTPError.NotFound. Since this response interacts with the filesystem, it can fail with other arbitrary Throwable failures; you'll probably need to catch these and convert them to HTTPError failures.

def fromStream(stream: Stream[Nothing, Chunk[Byte]], size: Long, contentType: String, status: Status, ifModifiedSince: Option[String], headers: List[(String, String)]): UIO[Response]
def html(body: String, status: Status, headers: List[(String, String)], charset: Charset): Response

Build a caching layer which can memoize and cache responses in memory for the duration of the server's lifetime.

Build a caching layer which can memoize and cache responses in memory for the duration of the server's lifetime.

def plain(body: String, status: Status, headers: List[(String, String)], charset: Charset): Response
def websocket(req: Request, output: Stream[Throwable, Frame], headers: List[(String, String)]): IO[BadRequest, WebsocketResponse]

Start a websocket request from a stream of uzhttp.websocket.Frame s.

Start a websocket request from a stream of uzhttp.websocket.Frame s.

Value Params
headers

Any additional headers to include in the response.

output

A stream of websocket uzhttp.websocket.Frame s to be sent to the client.

req

The websocket request that initiated this response.

Concrete fields