Public Member Functions | Public Attributes

wibble::net::http::Request Struct Reference

#include <http.h>

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

List of all members.

Public Member Functions

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

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".
bool response_started
 true if some response has already been sent to the client
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

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

Member Function Documentation

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

Discard all input from the socket.

References sock.

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

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.

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.

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 sock.

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

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().

bool wibble::net::http::Request::read_method (  ) 
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.

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().

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

Send the HTTP date header.

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

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

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().

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() 
)
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().

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, and send().

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

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

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

Referenced by read_headers(), and read_method().

Referenced by set_cgi_env().

Referenced by set_cgi_env().

Referenced by read_request(), and set_cgi_env().

true if some response has already been sent to the client

Referenced by send_status_line().

Referenced by set_cgi_env().

Referenced by set_cgi_env().

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

Referenced by send_server_header(), and set_cgi_env().

Referenced by read_method().


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