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

`#include <http.h>`

Collaboration diagram for wibble::net::http::Request:
[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

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

References wibble::Splitter::begin(), wibble::Splitter::end(), method, mime_reader, wibble::net::mime::Reader::read_line(), sock, space_splitter, wibble::str::toupper(), url, and version.

Referenced by 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.

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(), send(), and wibble::sys::fs::size().

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

Send a string as result.

References wibble::str::fmtf(), send(), send_date_header(), send_extra_response_headers(), send_server_header(), and send_status_line().

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

Referenced by send_extra_response_headers().

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

Referenced by wibble::net::http::Params::parse_post(), read_headers(), read_request(), and set_cgi_env().

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

Referenced by wibble::net::http::Params::parse_get_or_post(), read_method(), read_request(), and set_cgi_env().

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

Referenced by read_headers(), and read_method().

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

Referenced by path_info_head(), pop_path_info(), read_request(), and set_cgi_env().

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

Referenced by set_cgi_env().

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

Referenced by set_cgi_env().

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

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

Referenced by read_request(), and set_cgi_env().

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

true if some response has already been sent to the client

Referenced by send_status_line().

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

Referenced by pop_path_info(), read_request(), wibble::net::http::error404::send(), and set_cgi_env().

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

Referenced by set_cgi_env().

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

Referenced by set_cgi_env().

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

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

Referenced by discard_input(), wibble::net::http::Params::parse_multipart(), read_buf(), read_headers(), read_method(), and send().

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

Referenced by read_method().

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

Referenced by wibble::net::http::Params::parse_get_or_post(), read_method(), and read_request().

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

Referenced by read_method(), read_request(), and set_cgi_env().

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

- http.h
- http.cpp