sptk2 logo
SPTK Home Page
Public Types | Public Member Functions | List of all members
sptk::HttpReader Class Reference

#include <HttpReader.h>

Public Types

enum class  State : unsigned {
  READY = 0 , READING_HEADERS = 1 , READING_DATA = 2 , COMPLETED = 4 ,
  READ_ERROR = 8
}
 
enum class  ReadMode { REQUEST , RESPONSE }
 

Public Member Functions

State getReaderState () const
 
HttpHeaders & getHttpHeaders ()
 
String httpHeader (const String &headerName) const
 
 HttpReader (TCPSocket &socket, Buffer &output, ReadMode readMode)
 
TCPSocketsocket ()
 
Bufferoutput ()
 
void read ()
 
bool readHttpRequest ()
 
void readHttpHeaders ()
 
int readAll (std::chrono::milliseconds timeout)
 
int getStatusCode () const
 
const StringgetStatusText () const
 
String getRequestType () const
 
String getRequestURL () const
 
void close ()
 

Detailed Description

HTTP response reader

Designed to be able accepting asynchronous data

Member Enumeration Documentation

◆ ReadMode

enum class sptk::HttpReader::ReadMode
strong

Read mode, defines is it HTTP request (GET, POST, etc) or response.

◆ State

enum class sptk::HttpReader::State : unsigned
strong

State of the response reader

Enumerator
READY 

Reader is ready to start.

READING_HEADERS 

Reader is reading headers.

READING_DATA 

Reader is reading data.

COMPLETED 

Reading completed.

READ_ERROR 

Reading error (transfer terminated prematurely)

Constructor & Destructor Documentation

◆ HttpReader()

sptk::HttpReader::HttpReader ( TCPSocket socket,
Buffer output,
ReadMode  readMode 
)

Constructor

Parameters
socketSocket to read from
outputOutput data buffer

Member Function Documentation

◆ getHttpHeaders()

HttpHeaders & sptk::HttpReader::getHttpHeaders ( )

Access to response headers

◆ getReaderState()

State sptk::HttpReader::getReaderState ( ) const

Returns current reader state

◆ getStatusCode()

int sptk::HttpReader::getStatusCode ( ) const

Status code getter

Returns
status code

◆ getStatusText()

const String & sptk::HttpReader::getStatusText ( ) const

Status text getter

Returns
status text

◆ httpHeader()

String sptk::HttpReader::httpHeader ( const String headerName) const

Read-only access to response headers by name

Parameters
headerNameHeader name

◆ output()

Buffer & sptk::HttpReader::output ( )

Get output buffer

Returns
output buffer

◆ read()

void sptk::HttpReader::read ( )

Read data that can be read completely

◆ readAll()

int sptk::HttpReader::readAll ( std::chrono::milliseconds  timeout)

Read HTTP headers and data after socket is just connected. For requests, received by server, call readHttpRequest() first

Parameters
timeoutRead timeout
Returns
HTTP status code

◆ readHttpHeaders()

void sptk::HttpReader::readHttpHeaders ( )

Read headers that can be read completely

◆ readHttpRequest()

bool sptk::HttpReader::readHttpRequest ( )

Read HTTP request string

◆ socket()

TCPSocket & sptk::HttpReader::socket ( )

Get read socket

Returns
socket to read from

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

Fri Oct 14 2022 09:58:43: SPTK 5.4.1