The manakai project

Web::Transport::Response

Responses

SYNOPSIS

  if ($res->is_network_error) {
    warn $res->network_error_message;
  } else {
    warn $res->status, "\t", $res->status_text;
  }

DESCRIPTION

The Web::Transport::Response object represents a response, to be returned by Web::Transport::Connection and Web::Transport::WSClient.

METHODS

The following methods are available:

$boolean = $res->is_network_error

Whether the response represents a network error or not. A network error is a fatal error of the connection, including failures to establish a connection, non-recoverable parsing errors of an HTTP message, and unexpected termination of connection.

$string = $res->network_error_message

A human-readable short description of the network error, if any.

$integer = $res->status

If the response represents an HTTP response, the status code of the response.

If the response represents a WebSocket connection close event, the WebSocket connection close code.

$integer = $res->ws_code

The WebSocket connection close code. Unlike $res->status, this method can be used when the response does not represent a WebSocket connection close event (e.g. network error).

$string = $res->status_text

If the response represents an HTTP response, the reason phrase of the response (bytes).

If the response represents a WebSocket connection close event, the WebSocket connection close reason (text).

$text = $res->ws_reason

The WebSocket connection close reason. Unlike $res->status_text, this method can be used when the response does not represent a WebSocket connection close event (e.g. network error).

$boolean = $res->ws_closed_cleanly

Whether the WebSocket connection has been closed cleanly or not. This method can be used when the response does not represent a WebSocket connection close event (e.g. network error).

$value_bytes = $res->header ($name_bytes)

Returns the header value for the header name specified in the argument, as byte strings. If there are multiple headers with that name, their values are concatenated with , (0x2C 0x20). If there is no such header, undef is returned instead.

This method is appropriate for most headers.

[$value_bytes, ...] = $res->header_all ($name_bytes)

Returns the header value for the header name specified in the argument, as an array reference of header values as byte strings, preserving the order in the headers. If there is no such header, an empty array reference is returned.

This method is appropriate for limited kinds of headers, such as Set-Cookie.

$bytes = $res->body_bytes

The response body, as a string of bytes, if any.

This method throws an exception if the response is created with a body stream.

$readable = $res->body_stream

The response body, as a ReadableStream.

This method throws an exception unless the response is created with a body stream.

If application receives a response created with a body stream, it must read the stream until the end of the stream is detected or cancel the stream. Otherwise the HTTP connection cannot be used for any subsequent request or be closed gracefully.

$boolean = $res->incomplete

Whether it is an incomplete message or not.

$text = '' . $res
$text = $res->stringify

A human-readable short string describing the response.

The stringify operation of the response object is overloaded such that throwing the response as (uncaught) exception would print the string.

AUTHOR

Wakaba <wakaba@suikawiki.org>.

LICENSE

Copyright 2016-2020 Wakaba <wakaba@suikawiki.org>.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.