Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
pulp::runtime::HttpStream Class Reference

HTTP response as a readable Stream. More...

#include <network_stream.hpp>

Classes

struct  Request

Public Member Functions

 HttpStream ()=default
 HttpStream (const Request &request)
bool fetch (const Request &request)
 Issue a new request, replacing any prior state.
StreamResult read (std::uint8_t *buffer, std::size_t size) override
 Read up to size bytes into buffer.
StreamResult write (const std::uint8_t *buffer, std::size_t size) override
 Write up to size bytes from buffer.
void close () override
 Close the stream. Idempotent.
bool is_open () const override
 True while the stream is usable for read/write.
int status_code () const
 HTTP status code of the response, or 0 if the request failed.
const std::map< std::string, std::string > & headers () const
 Parsed response headers (lowercased keys are not normalized — they come through verbatim from cpp-httplib).
const std::string & transport_error () const
 Non-empty when the request failed locally (network error, DNS, etc.).
bool eof () const
 True when the HTTP response body was fully consumed by read().

Static Public Member Functions

static std::unique_ptr< HttpStream > get (std::string_view url, int timeout_seconds=30)
 Convenience factory for GET requests.
static std::unique_ptr< HttpStream > post (std::string_view url, std::string_view body, std::string_view content_type="application/json", int timeout_seconds=30)
 Convenience factory for POST requests.

Detailed Description

HTTP response as a readable Stream.

The request is issued eagerly in the constructor (or via get/post) and the body is exposed through the Stream read() contract. Partial reads return chunks from the body buffer; status_code() and headers() are available once construction completes.

HttpStream is currently read-only. Request bodies are provided up front by post(), so write() returns Invalid.

Constructor & Destructor Documentation

◆ HttpStream() [1/2]

pulp::runtime::HttpStream::HttpStream ( )
default

◆ HttpStream() [2/2]

pulp::runtime::HttpStream::HttpStream ( const Request & request)
explicit

Member Function Documentation

◆ close()

void pulp::runtime::HttpStream::close ( )
overridevirtual

Close the stream. Idempotent.

Implements pulp::runtime::Stream.

◆ eof()

bool pulp::runtime::HttpStream::eof ( ) const

True when the HTTP response body was fully consumed by read().

◆ fetch()

bool pulp::runtime::HttpStream::fetch ( const Request & request)

Issue a new request, replacing any prior state.

◆ get()

std::unique_ptr< HttpStream > pulp::runtime::HttpStream::get ( std::string_view url,
int timeout_seconds = 30 )
static

Convenience factory for GET requests.

◆ headers()

const std::map< std::string, std::string > & pulp::runtime::HttpStream::headers ( ) const
inline

Parsed response headers (lowercased keys are not normalized — they come through verbatim from cpp-httplib).

◆ is_open()

bool pulp::runtime::HttpStream::is_open ( ) const
overridevirtual

True while the stream is usable for read/write.

Implements pulp::runtime::Stream.

◆ post()

std::unique_ptr< HttpStream > pulp::runtime::HttpStream::post ( std::string_view url,
std::string_view body,
std::string_view content_type = "application/json",
int timeout_seconds = 30 )
static

Convenience factory for POST requests.

◆ read()

StreamResult pulp::runtime::HttpStream::read ( std::uint8_t * buffer,
std::size_t size )
overridevirtual

Read up to size bytes into buffer.

Returns how many bytes were written, or an error. buffer may be partially filled on error.

Implements pulp::runtime::Stream.

◆ status_code()

int pulp::runtime::HttpStream::status_code ( ) const
inline

HTTP status code of the response, or 0 if the request failed.

◆ transport_error()

const std::string & pulp::runtime::HttpStream::transport_error ( ) const
inline

Non-empty when the request failed locally (network error, DNS, etc.).

◆ write()

StreamResult pulp::runtime::HttpStream::write ( const std::uint8_t * buffer,
std::size_t size )
overridevirtual

Write up to size bytes from buffer.

Returns how many bytes were consumed. Partial writes are permitted — callers loop until satisfied or treat the short return as backpressure.

Implements pulp::runtime::Stream.


The documentation for this class was generated from the following file: