Bitcoin Core 31.99.0
P2P Digital Currency
Public Types | Public Member Functions | Public Attributes | Private Attributes | List of all members
http_bitcoin::HTTPRequest Class Reference

#include <httpserver.h>

Collaboration diagram for http_bitcoin::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. More...
 
void WriteReply (HTTPStatusCode status, std::span< const std::byte > reply_body={})
 
void WriteReply (HTTPStatusCode status, std::string_view reply_body_view)
 
std::string GetURI () const
 
CService GetPeer () const
 
HTTPRequestMethod GetRequestMethod () const
 
std::optional< std::string > GetQueryParameter (std::string_view key) const
 
std::pair< bool, std::string > GetHeader (std::string_view hdr) const
 
std::string ReadBody () const
 
void WriteHeader (std::string &&hdr, std::string &&value)
 
State GetState () const
 
void SetState (State state)
 
bool LoadControlData (LineReader &reader)
 Methods that attempt to parse HTTP request fields line-by-line from a receive buffer. More...
 
bool LoadHeaders (LineReader &reader)
 
bool LoadBody (LineReader &reader)
 

Public Attributes

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

Private Attributes

State m_state = State::Init
 

Detailed Description

Definition at line 159 of file httpserver.h.

Member Enumeration Documentation

◆ State

Enumerator
Init 
NeedsHeaders 
NeedsBody 
Complete 
Error 

Definition at line 208 of file httpserver.h.

Constructor & Destructor Documentation

◆ HTTPRequest() [1/2]

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

Definition at line 174 of file httpserver.h.

◆ HTTPRequest() [2/2]

http_bitcoin::HTTPRequest::HTTPRequest ( )
inlineexplicit

Construct with a null client for unit tests.

Definition at line 176 of file httpserver.h.

Member Function Documentation

◆ GetHeader()

std::pair< bool, std::string > http_bitcoin::HTTPRequest::GetHeader ( std::string_view  hdr) const

Definition at line 696 of file httpserver.cpp.

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

◆ GetPeer()

CService http_bitcoin::HTTPRequest::GetPeer ( ) const

Definition at line 655 of file httpserver.cpp.

Here is the caller graph for this function:

◆ GetQueryParameter()

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

Definition at line 664 of file httpserver.cpp.

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

◆ GetRequestMethod()

HTTPRequestMethod http_bitcoin::HTTPRequest::GetRequestMethod ( ) const
inline

Definition at line 202 of file httpserver.h.

Here is the caller graph for this function:

◆ GetState()

State http_bitcoin::HTTPRequest::GetState ( ) const
inline

Definition at line 215 of file httpserver.h.

Here is the caller graph for this function:

◆ GetURI()

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

Definition at line 200 of file httpserver.h.

Here is the caller graph for this function:

◆ LoadBody()

bool http_bitcoin::HTTPRequest::LoadBody ( LineReader reader)

Definition at line 433 of file httpserver.cpp.

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

◆ LoadControlData()

bool http_bitcoin::HTTPRequest::LoadControlData ( 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 380 of file httpserver.cpp.

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

◆ LoadHeaders()

bool http_bitcoin::HTTPRequest::LoadHeaders ( LineReader reader)

Definition at line 428 of file httpserver.cpp.

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

◆ ReadBody()

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

Definition at line 205 of file httpserver.h.

Here is the caller graph for this function:

◆ SetState()

void http_bitcoin::HTTPRequest::SetState ( State  state)
inline

Definition at line 216 of file httpserver.h.

Here is the caller graph for this function:

◆ WriteHeader()

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

Definition at line 702 of file httpserver.cpp.

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

◆ WriteReply() [1/2]

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

Definition at line 537 of file httpserver.cpp.

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

◆ WriteReply() [2/2]

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

Definition at line 193 of file httpserver.h.

Here is the call graph for this function:

Member Data Documentation

◆ m_body

std::string http_bitcoin::HTTPRequest::m_body

Definition at line 166 of file httpserver.h.

◆ m_chunk_read

uint64_t http_bitcoin::HTTPRequest::m_chunk_read {0}

Definition at line 224 of file httpserver.h.

◆ m_chunk_size

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

Definition at line 221 of file httpserver.h.

◆ m_client

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

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

Definition at line 169 of file httpserver.h.

◆ m_headers

HTTPHeaders http_bitcoin::HTTPRequest::m_headers

Definition at line 165 of file httpserver.h.

◆ m_method

HTTPRequestMethod http_bitcoin::HTTPRequest::m_method

Definition at line 162 of file httpserver.h.

◆ m_response_headers

HTTPHeaders http_bitcoin::HTTPRequest::m_response_headers

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

Definition at line 172 of file httpserver.h.

◆ m_state

State http_bitcoin::HTTPRequest::m_state = State::Init
private

Definition at line 227 of file httpserver.h.

◆ m_target

std::string http_bitcoin::HTTPRequest::m_target

Definition at line 163 of file httpserver.h.

◆ m_version

HTTPVersion http_bitcoin::HTTPRequest::m_version

Definition at line 164 of file httpserver.h.


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