Bitcoin Core 32.1.0
P2P Digital Currency
Loading...
Searching...
No Matches
HTTPRequest Class Reference

#include <httpserver.h>

Collaboration diagram for HTTPRequest:
[legend]

Public Types

enum class  State {
  Init , NeedsHeaders , NeedsBody , Complete ,
  Error
}

Public Member Functions

 HTTPRequest (const std::shared_ptr< HTTPRemoteClient > &client)
 HTTPRequest ()
 Construct with a null client for unit tests.
void WriteReply (HTTPStatusCode status, std::span< const std::byte > reply_body={})
void WriteReply (HTTPStatusCode status, std::string_view reply_body_view)
const HTTPVersion & GetVersion () const
std::shared_ptr< HTTPRemoteClient > GetClient () const
std::string GetURI () const
CService GetPeer () const
HTTPRequestMethod GetRequestMethod () const
std::optional< std::string > GetQueryParameter (std::string_view key) const
std::optional< std::string > GetHeader (std::string_view hdr) const
std::string ReadBody () const
void WriteHeader (std::string &&hdr, std::string &&value)
std::optional< uint64_t > GetChunkSize () const
uint64_t GetChunkProgress () const
State GetState () const
void SetState (State state)
bool LoadControlData (util::LineReader &reader)
 Methods that attempt to parse HTTP request fields line-by-line from a receive buffer.
bool LoadHeaders (util::LineReader &reader)
bool LoadBody (util::LineReader &reader)

Private Attributes

HTTPRequestMethod m_method
std::string m_target
HTTPVersion m_version
HTTPHeaders m_headers
std::string m_body
std::weak_ptr< HTTPRemoteClient > m_client
 Pointer to the client that made the request so we know who to respond to.
HTTPHeaders m_response_headers
 Response headers may be set in advance before response body is known.
std::optional< uint64_t > m_chunk_size
uint64_t m_chunk_read {0}
State m_state = State::Init

Detailed Description

Definition at line 154 of file httpserver.h.

Member Enumeration Documentation

◆ State

enum class HTTPRequest::State
strong
Enumerator
Init 
NeedsHeaders 
NeedsBody 
Complete 
Error 

Definition at line 196 of file httpserver.h.

Constructor & Destructor Documentation

◆ HTTPRequest() [1/2]

HTTPRequest::HTTPRequest ( const std::shared_ptr< HTTPRemoteClient > & client)
inlineexplicit

Definition at line 157 of file httpserver.h.

◆ HTTPRequest() [2/2]

HTTPRequest::HTTPRequest ( )
inlineexplicit

Construct with a null client for unit tests.

Definition at line 159 of file httpserver.h.

Member Function Documentation

◆ GetChunkProgress()

uint64_t HTTPRequest::GetChunkProgress ( ) const
inline

Definition at line 194 of file httpserver.h.

◆ GetChunkSize()

std::optional< uint64_t > HTTPRequest::GetChunkSize ( ) const
inline

Definition at line 193 of file httpserver.h.

◆ GetClient()

std::shared_ptr< HTTPRemoteClient > HTTPRequest::GetClient ( ) const
inline

Definition at line 182 of file httpserver.h.

◆ GetHeader()

std::optional< std::string > HTTPRequest::GetHeader ( std::string_view hdr) const

Definition at line 698 of file httpserver.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetPeer()

CService HTTPRequest::GetPeer ( ) const

Definition at line 657 of file httpserver.cpp.

Here is the caller graph for this function:

◆ GetQueryParameter()

std::optional< std::string > HTTPRequest::GetQueryParameter ( std::string_view key) const

Definition at line 666 of file httpserver.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetRequestMethod()

HTTPRequestMethod HTTPRequest::GetRequestMethod ( ) const
inline

Definition at line 188 of file httpserver.h.

Here is the caller graph for this function:

◆ GetState()

State HTTPRequest::GetState ( ) const
inline

Definition at line 203 of file httpserver.h.

Here is the caller graph for this function:

◆ GetURI()

std::string HTTPRequest::GetURI ( ) const
inline

Definition at line 186 of file httpserver.h.

Here is the caller graph for this function:

◆ GetVersion()

const HTTPVersion & HTTPRequest::GetVersion ( ) const
inline

Definition at line 181 of file httpserver.h.

Here is the caller graph for this function:

◆ LoadBody()

bool HTTPRequest::LoadBody ( util::LineReader & reader)

Definition at line 431 of file httpserver.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LoadControlData()

bool HTTPRequest::LoadControlData ( util::LineReader & reader)

Methods that attempt to parse HTTP request fields line-by-line from a receive buffer.

Parameters
[in]readerA LineReader object constructed over a span of data.
Returns
true If the request field was parsed. false If there was not enough data in the buffer to complete the field.
Exceptions
std::runtime_errorif data is invalid.

Definition at line 378 of file httpserver.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LoadHeaders()

bool HTTPRequest::LoadHeaders ( util::LineReader & reader)

Definition at line 426 of file httpserver.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReadBody()

std::string HTTPRequest::ReadBody ( ) const
inline

Definition at line 191 of file httpserver.h.

Here is the caller graph for this function:

◆ SetState()

void HTTPRequest::SetState ( State state)
inline

Definition at line 204 of file httpserver.h.

Here is the caller graph for this function:

◆ WriteHeader()

void HTTPRequest::WriteHeader ( std::string && hdr,
std::string && value )

Definition at line 703 of file httpserver.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteReply() [1/2]

void HTTPRequest::WriteReply ( HTTPStatusCode status,
std::span< const std::byte > reply_body = {} )

Definition at line 535 of file httpserver.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteReply() [2/2]

void HTTPRequest::WriteReply ( HTTPStatusCode status,
std::string_view reply_body_view )
inline

Definition at line 176 of file httpserver.h.

Here is the call graph for this function:

Member Data Documentation

◆ m_body

std::string HTTPRequest::m_body
private

Definition at line 211 of file httpserver.h.

◆ m_chunk_read

uint64_t HTTPRequest::m_chunk_read {0}
private

Definition at line 225 of file httpserver.h.

◆ m_chunk_size

std::optional<uint64_t> HTTPRequest::m_chunk_size
private

Definition at line 222 of file httpserver.h.

◆ m_client

std::weak_ptr<HTTPRemoteClient> HTTPRequest::m_client
private

Pointer to the client that made the request so we know who to respond to.

Definition at line 214 of file httpserver.h.

◆ m_headers

HTTPHeaders HTTPRequest::m_headers
private

Definition at line 210 of file httpserver.h.

◆ m_method

HTTPRequestMethod HTTPRequest::m_method
private

Definition at line 207 of file httpserver.h.

◆ m_response_headers

HTTPHeaders HTTPRequest::m_response_headers
private

Response headers may be set in advance before response body is known.

Definition at line 217 of file httpserver.h.

◆ m_state

State HTTPRequest::m_state = State::Init
private

Definition at line 227 of file httpserver.h.

◆ m_target

std::string HTTPRequest::m_target
private

Definition at line 208 of file httpserver.h.

◆ m_version

HTTPVersion HTTPRequest::m_version
private

Definition at line 209 of file httpserver.h.


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