http_response.h
//
// Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
//
// See accompanying file COPYING.TXT file for licensing details.
//
#ifndef CPPCMS_HTTP_RESPONSE_H
#define CPPCMS_HTTP_RESPONSE_H
#include <cppcms/defs.h>
#include <booster/noncopyable.h>
#include <booster/hold_ptr.h>
#include <string>
#include <iostream>
#include <cppcms/cstdint.h>
namespace cppcms {
class cache_interface;
namespace impl { namespace cgi { class connection; }}
namespace http {
class context;
class cookie;
class CPPCMS_API response : public booster::noncopyable {
public:
typedef enum {
continue_transfer = 100,
switching_protocol = 101,
ok = 200,
created = 201,
accepted = 202,
non_authoritative_information = 203,
no_content = 204,
reset_content = 205,
partial_content = 206,
multiple_choices = 300,
moved_permanently = 301,
found = 302,
see_other = 303,
not_modified = 304,
use_proxy = 305,
temporary_redirect = 307,
bad_request = 400,
unauthorized = 401,
payment_required = 402,
forbidden = 403,
not_found = 404,
method_not_allowed = 405,
not_acceptable = 406,
proxy_authentication_required = 407,
request_time_out = 408,
conflict = 409,
gone = 410,
precondition_failed = 412,
request_entity_too_large = 413,
request_uri_too_large = 414,
unsupported_media_type = 415,
requested_range_not_satisfiable = 416,
expectation_failed = 417,
internal_server_error = 500,
not_implemented = 501,
bad_gateway = 502,
service_unavailable = 503,
gateway_timeout = 504,
http_version_not_supported = 505
} status_type;
typedef enum {
normal,
nogzip,
raw,
asynchronous,
asynchronous_raw
} io_mode_type;
// Standard HTTP Response Headers RFC 2616
void accept_ranges(std::string const &);
void age(unsigned seconds);
void allow(std::string const &);
void cache_control(std::string const &);
void content_encoding(std::string const &);
void content_language(std::string const &);
void content_length(unsigned long long len);
void content_location(std::string const &);
void content_md5(std::string const &);
void content_range(std::string const &);
void content_type(std::string const &);
void date(time_t);
void etag(std::string const &);
void expires(time_t t);
void last_modified(time_t t);
void location(std::string const &);
void pragma(std::string const &);
void proxy_authenticate(std::string const &);
void retry_after(std::string const &);
void retry_after(unsigned);
void status(int code);
void status(int code,std::string const &message);
void trailer(std::string const &);
void transfer_encoding(std::string const &);
void vary(std::string const &);
void via(std::string const &);
void warning(std::string const &);
void www_authenticate(std::string const &);
void set_header(std::string const &name,std::string const &value);
std::string get_header(std::string const &name);
void erase_header(std::string const &h);
void set_content_header(std::string const &content_type);
void set_html_header();
void set_xhtml_header();
void set_plain_text_header();
void set_redirect_header(std::string const &location,int status = found);
void set_cookie(cookie const &);
void make_error_response(int stat,std::string const &msg = std::string());
io_mode_type io_mode();
void io_mode(io_mode_type);
std::ostream &out();
static std::string make_http_time(time_t);
static char const *status_to_string(int status);
bool some_output_was_written();
void finalize();
response(context &);
~response();
private:
friend class impl::cgi::connection;
friend class ::cppcms::cache_interface;
void copy_to_cache();
std::string copied_data();
bool need_gzip();
std::pair<char const *,size_t> output();
void write_http_headers(std::ostream &);
std::string get_async_chunk();
struct _data;
booster::hold_ptr<_data> d;
context &context_;
std::ostream *stream_;
io_mode_type io_mode_;
uint32_t disable_compression_ : 1;
uint32_t ostream_requested_ : 1;
uint32_t copy_to_cache_ : 1;
uint32_t finalized_ : 1;
uint32_t reserved_ : 28;
};
} /* http */
} /* cppcms */
#endif
booster::locale::as::date
std::ios_base & date(std::ios_base &ios)
Definition: formatting.h:319
cppcms::http::content_type
Class that represents parsed Content-Type header, this is immutable class. Once it is created its val...
Definition: http_content_type.h:23
booster::hold_ptr< _data >
cppcms::http::response::normal
Synchronous IO. Write the request, it is buffered and possible compressed using gzip.
Definition: http_response.h:84
cppcms::http::context
context is a central class that holds all specific connection related information. It encapsulates CGI request and response, cache, session and locale information
Definition: http_context.h:45
cppcms::http::response
this class represents all HTTP/CGI response related API, generation of output content and HTTP header...
Definition: http_response.h:31
booster::locale::message
basic_message< char > message
Definition: message.h:494
cppcms::http::response::nogzip
Same as normal but disable gzip compression.
Definition: http_response.h:85
cppcms::http::cookie
Class that represents single HTTP Cookie Generally used in context of http::request and http::respons...
Definition: http_cookie.h:27
booster::noncopyable
This class makes impossible to copy any class derived from this one.
Definition: noncopyable.h:15