wibble  1.1
Public Member Functions | Public Attributes | List of all members
wibble::net::http::Request Struct Reference

#include <http.h>

Collaboration diagram for wibble::net::http::Request:
Collaboration graph
[legend]

Public Member Functions

 Request ()
 
bool read_request ()
 Read request method and headers from sock. More...
 
bool read_buf (std::string &res, size_t size)
 Read a fixed amount of data from the file descriptor. More...
 
bool read_method ()
 
bool read_headers ()
 Read HTTP headers. More...
 
void set_cgi_env ()
 Set the CGI environment variables for the current process using this request. More...
 
void send (const std::string &buf)
 Send the content of buf, verbatim, to the client. More...
 
void send_status_line (int code, const std::string &msg, const std::string &version="HTTP/1.0")
 Send the HTTP status line. More...
 
void send_server_header ()
 Send the HTTP server header. More...
 
void send_date_header ()
 Send the HTTP date header. More...
 
void send_extra_response_headers ()
 Send headers in extra_response_headers. More...
 
void send_result (const std::string &content, const std::string &content_type="text/html; charset=utf-8", const std::string &filename=std::string())
 Send a string as result. More...
 
void discard_input ()
 Discard all input from the socket. More...
 
std::string pop_path_info ()
 Remove the first component from path_info, append it to script_name and return it. More...
 
std::string path_info_head ()
 Return the first component from path_info. More...
 

Public Attributes

int sock
 
std::string peer_hostname
 
std::string peer_hostaddr
 
std::string peer_port
 
std::string server_name
 
std::string server_port
 
std::string script_name
 
std::string path_info
 
std::string query_string
 
std::string server_software
 String to use as server software "NAME/version". More...
 
bool response_started
 true if some response has already been sent to the client More...
 
std::string method
 
std::string url
 
std::string version
 
std::map< std::string, std::string > headers
 
wibble::Splitter space_splitter
 
wibble::net::mime::Reader mime_reader
 
std::map< std::string, std::string > extra_response_headers
 

Constructor & Destructor Documentation

◆ Request()

wibble::net::http::Request::Request ( )

Member Function Documentation

◆ discard_input()

void wibble::net::http::Request::discard_input ( )

Discard all input from the socket.

References sock.

Referenced by wibble::net::http::Params::parse_post().

◆ path_info_head()

std::string wibble::net::http::Request::path_info_head ( )

Return the first component from path_info.

If path_info if empty or only consisting of '/', returns the empty string.

References wibble::list::end(), and path_info.

◆ pop_path_info()

std::string wibble::net::http::Request::pop_path_info ( )

Remove the first component from path_info, append it to script_name and return it.

If path_info if empty or only consisting of '/', returns the empty string.

References wibble::list::end(), wibble::str::joinpath(), path_info, and script_name.

◆ read_buf()

bool wibble::net::http::Request::read_buf ( std::string &  res,
size_t  size 
)

Read a fixed amount of data from the file descriptor.

Returns
true if all the data were read, false if EOF was encountered before the end of the buffer

References wibble::sys::fs::size(), and sock.

Referenced by wibble::net::http::Params::parse_post().

◆ read_headers()

bool wibble::net::http::Request::read_headers ( )

Read HTTP headers.

Returns
true if there still data to read and headers are terminated by an empty line, false if headers are terminated by EOF

References headers, mime_reader, wibble::net::mime::Reader::read_headers(), and sock.

Referenced by read_request().

◆ read_method()

bool wibble::net::http::Request::read_method ( )

◆ read_request()

bool wibble::net::http::Request::read_request ( )

Read request method and headers from sock.

Sock will be positioned at the beginning of the request body, after the empty line that follows the header.

The request URL will be parsed in script_name, path_info and query_string. At the start, script_name is always / and path_info is the rest of the path in the url. One can move path components from path_info to script_name as the request is processed.

Returns
true if the request has been read, false if EOF was found before the end of the headers.

References headers, method, path_info, query_string, read_headers(), read_method(), script_name, url, and version.

◆ send()

void wibble::net::http::Request::send ( const std::string &  buf)

Send the content of buf, verbatim, to the client.

References sock.

Referenced by wibble::net::http::error::send(), send_date_header(), send_extra_response_headers(), send_result(), send_server_header(), and send_status_line().

◆ send_date_header()

void wibble::net::http::Request::send_date_header ( )

Send the HTTP date header.

References wibble::grcal::date::now(), send(), and wibble::sys::fs::size().

Referenced by wibble::net::http::error::send(), and send_result().

◆ send_extra_response_headers()

void wibble::net::http::Request::send_extra_response_headers ( )

Send headers in extra_response_headers.

References extra_response_headers, and send().

Referenced by wibble::net::http::error::send(), and send_result().

◆ send_result()

void wibble::net::http::Request::send_result ( const std::string &  content,
const std::string &  content_type = "text/html; charset=utf-8",
const std::string &  filename = std::string() 
)

◆ send_server_header()

void wibble::net::http::Request::send_server_header ( )

Send the HTTP server header.

References send(), and server_software.

Referenced by wibble::net::http::error::send(), and send_result().

◆ send_status_line()

void wibble::net::http::Request::send_status_line ( int  code,
const std::string &  msg,
const std::string &  version = "HTTP/1.0" 
)

Send the HTTP status line.

References response_started, send(), and version.

Referenced by wibble::net::http::error::send(), and send_result().

◆ set_cgi_env()

void wibble::net::http::Request::set_cgi_env ( )

Set the CGI environment variables for the current process using this request.

References headers, method, path_info, peer_hostaddr, peer_hostname, query_string, script_name, server_name, server_port, server_software, and version.

Member Data Documentation

◆ extra_response_headers

std::map<std::string, std::string> wibble::net::http::Request::extra_response_headers

◆ headers

std::map<std::string, std::string> wibble::net::http::Request::headers

◆ method

std::string wibble::net::http::Request::method

◆ mime_reader

wibble::net::mime::Reader wibble::net::http::Request::mime_reader

Referenced by read_headers(), and read_method().

◆ path_info

std::string wibble::net::http::Request::path_info

◆ peer_hostaddr

std::string wibble::net::http::Request::peer_hostaddr

Referenced by set_cgi_env().

◆ peer_hostname

std::string wibble::net::http::Request::peer_hostname

Referenced by set_cgi_env().

◆ peer_port

std::string wibble::net::http::Request::peer_port

◆ query_string

std::string wibble::net::http::Request::query_string

Referenced by read_request(), and set_cgi_env().

◆ response_started

bool wibble::net::http::Request::response_started

true if some response has already been sent to the client

Referenced by send_status_line().

◆ script_name

std::string wibble::net::http::Request::script_name

◆ server_name

std::string wibble::net::http::Request::server_name

Referenced by set_cgi_env().

◆ server_port

std::string wibble::net::http::Request::server_port

Referenced by set_cgi_env().

◆ server_software

std::string wibble::net::http::Request::server_software

String to use as server software "NAME/version".

Referenced by send_server_header(), and set_cgi_env().

◆ sock

int wibble::net::http::Request::sock

◆ space_splitter

wibble::Splitter wibble::net::http::Request::space_splitter

Referenced by read_method().

◆ url

std::string wibble::net::http::Request::url

◆ version

std::string wibble::net::http::Request::version

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