http namespace
Classes
-
template <typename Reader>class http_body_reader
- struct protocol_error
- Error raised for HTTP protocol parsing and transfer-framing failures.
- struct response_start
- Response head returned after sending a request.
- struct url
- Parsed URL pieces supported by the small HTTP client.
Functions
-
auto as_text(std::
span<const std:: byte> bytes) → std:: string_view - Reinterpret bytes as text.
-
auto has_header_token(const nxt::
http:: response_head& response, std:: string_view name, std:: string_view token) → bool - True when a comma-separated response header contains
token. -
auto header_value(const nxt::
http:: response_head& response, std:: string_view name) → std:: optional<std:: string_view> - Return the first matching response header value, case-insensitively.
- auto is_default_port(const url& url) → bool
- True when the URL uses its scheme's default port.
-
auto parse_chunk_size(std::
span<const std:: byte> line) → std:: size_t - Parse a hexadecimal chunk-size line.
-
auto parse_port(std::
string_view text) → std:: uint16_t - Parse a decimal TCP port.
-
auto parse_response_head(std::
span<const std:: byte> bytes) → nxt:: http:: response_head - Parse bytes up to an HTTP response-head boundary.
-
template <typename Reader>auto parse_sse_event(Reader& reader) → nxt::
task<std:: optional<nxt:: http:: server_sent_event>> -
auto parse_url(std::
string_view text) → url - Parse an HTTP or HTTPS URL into connection and request-target pieces.
-
template <typename Reader, typename OnChunk>auto read_chunked(Reader& reader, OnChunk on_chunk) → nxt::
task - Read a chunked transfer-encoded body.
-
template <typename Reader, typename OnChunk>auto read_content_length(Reader& reader, std::
size_t content_length, OnChunk on_chunk) → nxt:: task - Read exactly
content_lengthbytes and pass chunks toon_chunk. -
template <typename Reader>auto read_expected_crlf(Reader& reader) → nxt::
task - Read and validate an expected CRLF after chunk data.
-
template <typename Reader, typename OnChunk>auto read_response_body(Reader& reader, const response_
start& response, OnChunk on_chunk) → nxt:: task - Read the response body as chunks.
-
template <typename Reader, typename OnChunk>auto read_response_body_chunks(Reader& reader, const nxt::
http:: response_head& response, OnChunk on_chunk) → nxt:: task - Dispatch to the body reader required by the response headers.
-
template <typename Reader>auto read_response_text(Reader& reader, const response_
start& response) → nxt:: task<std:: string> - Read the full response body into a string.
-
template <typename Reader, typename OnChunk>auto read_until_eof(Reader& reader, OnChunk on_chunk) → nxt::
task - Read body bytes until the connection ends.
-
auto response_content_length(const nxt::
http:: response_head& response) → std:: optional<std:: size_t> - Parsed Content-Length header, when present.
-
auto response_content_type_is(const nxt::
http:: response_head& response, std:: string_view expected) → bool - True when the response Content-Type matches the expected media type.
-
auto response_is_chunked(const nxt::
http:: response_head& response) → bool - True when the response uses chunked transfer encoding.
-
auto response_status_is_success(const nxt::
http:: response_head& response) → bool - True for 2xx response status codes.
-
auto response_status_text(const nxt::
http:: response_head& response) → std:: string - Human-readable response status line.
-
template <typename Transport, typename Reader>auto send_request(Transport& transport, Reader& reader, const nxt::
http:: request& request) → nxt:: task<response_ start> - Write a request and parse the response head.
Function documentation
std:: string_view nxt:: io:: http:: as_text(std:: span<const std:: byte> bytes)
#include <nxtio/http.hpp>
Reinterpret bytes as text.
bool nxt:: io:: http:: has_header_token(const nxt:: http:: response_head& response,
std:: string_view name,
std:: string_view token)
#include <nxtio/http.hpp>
True when a comma-separated response header contains token.
std:: optional<std:: string_view> nxt:: io:: http:: header_value(const nxt:: http:: response_head& response,
std:: string_view name)
#include <nxtio/http.hpp>
Return the first matching response header value, case-insensitively.
bool nxt:: io:: http:: is_default_port(const url& url)
#include <nxtio/http.hpp>
True when the URL uses its scheme's default port.
std:: size_t nxt:: io:: http:: parse_chunk_size(std:: span<const std:: byte> line)
#include <nxtio/http.hpp>
Parse a hexadecimal chunk-size line.
std:: uint16_t nxt:: io:: http:: parse_port(std:: string_view text)
#include <nxtio/http.hpp>
Parse a decimal TCP port.
nxt:: http:: response_head nxt:: io:: http:: parse_response_head(std:: span<const std:: byte> bytes)
#include <nxtio/http.hpp>
Parse bytes up to an HTTP response-head boundary.
#include <nxtio/http.hpp>
template <typename Reader>
nxt:: task<std:: optional<nxt:: http:: server_sent_event>> nxt:: io:: http:: parse_sse_event(Reader& reader)
Pull one server-sent event from a buffered byte stream.
Returns std:: on clean end-of-stream. Reader is expected to be a byte_-shaped source with take_until("\n").
url nxt:: io:: http:: parse_url(std:: string_view text)
#include <nxtio/http.hpp>
Parse an HTTP or HTTPS URL into connection and request-target pieces.
#include <nxtio/http.hpp>
template <typename Reader, typename OnChunk>
nxt:: task nxt:: io:: http:: read_chunked(Reader& reader,
OnChunk on_chunk)
Read a chunked transfer-encoded body.
#include <nxtio/http.hpp>
template <typename Reader, typename OnChunk>
nxt:: task nxt:: io:: http:: read_content_length(Reader& reader,
std:: size_t content_length,
OnChunk on_chunk)
Read exactly content_length bytes and pass chunks to on_chunk.
#include <nxtio/http.hpp>
template <typename Reader>
nxt:: task nxt:: io:: http:: read_expected_crlf(Reader& reader)
Read and validate an expected CRLF after chunk data.
#include <nxtio/http.hpp>
template <typename Reader, typename OnChunk>
nxt:: task nxt:: io:: http:: read_response_body(Reader& reader,
const response_ start& response,
OnChunk on_chunk)
Read the response body as chunks.
#include <nxtio/http.hpp>
template <typename Reader, typename OnChunk>
nxt:: task nxt:: io:: http:: read_response_body_chunks(Reader& reader,
const nxt:: http:: response_head& response,
OnChunk on_chunk)
Dispatch to the body reader required by the response headers.
#include <nxtio/http.hpp>
template <typename Reader>
nxt:: task<std:: string> nxt:: io:: http:: read_response_text(Reader& reader,
const response_ start& response)
Read the full response body into a string.
#include <nxtio/http.hpp>
template <typename Reader, typename OnChunk>
nxt:: task nxt:: io:: http:: read_until_eof(Reader& reader,
OnChunk on_chunk)
Read body bytes until the connection ends.
std:: optional<std:: size_t> nxt:: io:: http:: response_content_length(const nxt:: http:: response_head& response)
#include <nxtio/http.hpp>
Parsed Content-Length header, when present.
bool nxt:: io:: http:: response_content_type_is(const nxt:: http:: response_head& response,
std:: string_view expected)
#include <nxtio/http.hpp>
True when the response Content-Type matches the expected media type.
bool nxt:: io:: http:: response_is_chunked(const nxt:: http:: response_head& response)
#include <nxtio/http.hpp>
True when the response uses chunked transfer encoding.
bool nxt:: io:: http:: response_status_is_success(const nxt:: http:: response_head& response)
#include <nxtio/http.hpp>
True for 2xx response status codes.
std:: string nxt:: io:: http:: response_status_text(const nxt:: http:: response_head& response)
#include <nxtio/http.hpp>
Human-readable response status line.
#include <nxtio/http.hpp>
template <typename Transport, typename Reader>
nxt:: task<response_ start> nxt:: io:: http:: send_request(Transport& transport,
Reader& reader,
const nxt:: http:: request& request)
Write a request and parse the response head.