8 #ifndef SERVLET_RESPONSE_H
9 #define SERVLET_RESPONSE_H
13 #include <experimental/string_view>
15 #include <servlet/cookie.h>
23 using std::experimental::string_view;
55 virtual void add_header(
const std::string &name,
const std::string &value) = 0;
68 template<
typename Clock,
typename Dur>
69 void add_date_header(
const std::string &name,
const std::chrono::time_point<Clock, Dur> &date)
71 add_date_header(name, std::chrono::duration_cast<std::chrono::seconds>(date.time_since_epoch()).count());
83 virtual void add_date_header(
const std::string &name,
long timeSec) = 0;
97 virtual void set_header(
const std::string &name,
const std::string &value) = 0;
113 template<
typename Clock,
typename Dur>
114 void set_date_header(
const std::string &name,
const std::chrono::time_point<Clock, Dur> &date)
116 set_date_header(name, std::chrono::duration_cast<std::chrono::seconds>(date.time_since_epoch()).count());
155 virtual string_view
get_header(
const std::string& name)
const = 0;
178 virtual void get_headers(
const std::string& name, std::vector<std::string>& headers)
const = 0;
185 virtual void get_headers(std::vector<std::pair<std::string, std::string>>& headers)
const = 0;
241 virtual void send_redirect(
const std::string &redirectURL) = 0;
580 void get_headers(
const std::string& name, std::vector<std::string>& headers)
const override
582 void get_headers(std::vector<std::pair<std::string, std::string>>& headers)
const override
620 #endif // SERVLET_RESPONSE_H
http_response & get_wrapped_request()
Returns wrapped response innstance.
Definition: response.h:564
static constexpr int SC_FOUND
Status code (302) indicating that the resource reside temporarily under a different URI...
Definition: response.h:355
virtual out_filter * filter()
Provides output filter for the http_response::get_output_stream.
Definition: response.h:611
virtual string_view get_content_type() const =0
Returns the content type used for the MIME body sent in this response.
void add_header(const std::string &name, const std::string &value) override
Adds a response header with the given name and value.
Definition: response.h:572
virtual bool contains_header(const std::string &name) const =0
Returns a boolean indicating whether the named response header has already been set.
static constexpr int SC_BAD_REQUEST
Status code (400) indicating the request sent by the client was syntactically incorrect.
Definition: response.h:387
Defines optional container objects and related methods.
static constexpr int SC_MULTIPLE_CHOICES
Status code (300) indicating that the requested resource corresponds to any one of a set of represent...
Definition: response.h:332
http_response_wrapper(http_response &resp)
Constructs a response adaptor wrapping the given response.
Definition: response.h:554
void add_date_header(const std::string &name, const std::chrono::time_point< Clock, Dur > &date)
Adds a response header with the given name and date-value.
Definition: response.h:69
virtual string_view get_header(const std::string &name) const =0
Return the value for the specified header, or empty string if this header has not been set...
static constexpr int SC_HTTP_VERSION_NOT_SUPPORTED
Status code (505) indicating that the server does not support or refuses to support the HTTP protocol...
Definition: response.h:533
static constexpr int SC_NOT_ACCEPTABLE
Status code (406) indicating that the resource identified by the request is only capable of generatin...
Definition: response.h:425
virtual void set_content_length(std::size_t len)=0
Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Conte...
static constexpr int SC_UNSUPPORTED_MEDIA_TYPE
Status code (415) indicating that the server is refusing to service the request because the entity of...
Definition: response.h:484
virtual void set_status(int sc)=0
Sets the status code for this response.
void set_date_header(const std::string &name, long timeSec) override
Sets a response header with the given name and date-value.
Definition: response.h:575
static constexpr int SC_RESET_CONTENT
Status code (205) indicating that the agent SHOULD reset the document view which caused the request t...
Definition: response.h:319
virtual void set_header(const std::string &name, const std::string &value)=0
Sets a response header with the given name and value.
static constexpr int SC_PRECONDITION_FAILED
Status code (412) indicating that the precondition given in one or more of the request-header fields ...
Definition: response.h:463
static constexpr int SC_REQUEST_ENTITY_TOO_LARGE
Status code (413) indicating that the server is refusing to process the request because the request e...
Definition: response.h:470
static constexpr int SC_INTERNAL_SERVER_ERROR
Status code (500) indicating an error inside the HTTP server which prevented it from fulfilling the r...
Definition: response.h:503
void set_content_length(std::size_t content_length) override
Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Conte...
Definition: response.h:587
static constexpr int SC_NO_CONTENT
Status code (204) indicating that the request succeeded but that there was no new information to retu...
Definition: response.h:313
Definitions for custom implementation of std::istream and std::ostream objects.
static constexpr int SC_PAYMENT_REQUIRED
Status code (402) reserved for future use.
Definition: response.h:398
void set_header(const std::string &name, const std::string &value) override
Sets a response header with the given name and value.
Definition: response.h:574
int get_status() const override
Get the HTTP status code for this Response.
Definition: response.h:592
void set_date_header(const std::string &name, const std::chrono::time_point< Clock, Dur > &date)
Sets a response header with the given name and date-value.
Definition: response.h:114
static constexpr int SC_LENGTH_REQUIRED
Status code (411) indicating that the request cannot be handled without a defined Content-Length...
Definition: response.h:456
Creates a cookie, a small amount of information sent by a servlet to a Web browser, saved by the browser, and later sent back to the server.
Definition: cookie.h:46
string_view get_content_type() const override
Returns the content type used for the MIME body sent in this response.
Definition: response.h:585
static constexpr int SC_NOT_MODIFIED
Status code (304) indicating that a conditional GET operation found that the resource was available a...
Definition: response.h:367
virtual void send_redirect(const std::string &redirectURL)=0
Sends a temporary redirect response to the client using the specified redirect location URL...
~http_response_wrapper() override
Overridden destructor.
Definition: response.h:558
void send_redirect(const std::string &redirectURL) override
Sends a temporary redirect response to the client using the specified redirect location URL...
Definition: response.h:589
static constexpr int SC_SEE_OTHER
Status code (303) indicating that the response to the request can be found under a different URI...
Definition: response.h:361
virtual void get_headers(const std::string &name, std::vector< std::string > &headers) const =0
Fills the std::vector with all the header values associated with the specified header name...
static constexpr int SC_PROXY_AUTHENTICATION_REQUIRED
Status code (407) indicating that the client MUST first authenticate itself with the proxy...
Definition: response.h:431
long get_date_header(const std::string &name) const override
Return the date value for the specified header, or -1 if this header has not been set...
Definition: response.h:579
virtual std::ostream & get_output_stream()=0
Returns a std::ostream suitable for writing binary data in the response.
static constexpr int SC_GONE
Status code (410) indicating that the resource is no longer available at the server and no forwarding...
Definition: response.h:450
const http_response & get_wrapped_request() const
Returns wrapped response innstance.
Definition: response.h:569
static constexpr int SC_CONTINUE
Status code (100) indicating the client can continue.
Definition: response.h:277
static constexpr int SC_REQUEST_TIMEOUT
Status code (408) indicating that the client did not produce a request within the time that the serve...
Definition: response.h:437
static constexpr int SC_CONFLICT
Status code (409) indicating that the request could not be completed due to a conflict with the curre...
Definition: response.h:443
virtual void set_content_type(const std::string &type)=0
Sets the content type of the response being sent to the client, if the response has not been committe...
static constexpr int SC_SERVICE_UNAVAILABLE
Status code (503) indicating that the HTTP server is temporarily overloaded, and unable to handle the...
Definition: response.h:521
static constexpr int SC_REQUEST_URI_TOO_LONG
Status code (414) indicating that the server is refusing to service the request because the Request-U...
Definition: response.h:477
static constexpr int SC_EXPECTATION_FAILED
Status code (417) indicating that the server could not meet the expectation given in the Expect reque...
Definition: response.h:496
static constexpr int SC_FORBIDDEN
Status code (403) indicating the server understood the request but refused to fulfill it...
Definition: response.h:404
bool contains_header(const std::string &name) const override
Returns a boolean indicating whether the named response header has already been set.
Definition: response.h:576
static constexpr int SC_PARTIAL_CONTENT
Status code (206) indicating that the server has fulfilled the partial GET request for the resource...
Definition: response.h:325
void get_headers(std::vector< std::pair< std::string, std::string >> &headers) const override
Fills the std::vector with all the response header values.
Definition: response.h:582
static constexpr int SC_TEMPORARY_REDIRECT
Status code (307) indicating that the requested resource resides temporarily under a different URI...
Definition: response.h:380
static constexpr int SC_OK
Status code (200) indicating the request succeeded normally.
Definition: response.h:289
static constexpr int SC_UNAUTHORIZED
Status code (401) indicating that the request requires HTTP authentication.
Definition: response.h:393
void set_content_type(const std::string &content_type) override
Sets the content type of the response being sent to the client, if the response has not been committe...
Definition: response.h:586
Abstract interface for output filter.
Definition: io_filter.h:72
static constexpr int SC_CREATED
Status code (201) indicating the request succeeded and created a new resource on the server...
Definition: response.h:295
virtual long get_date_header(const std::string &name) const =0
Return the date value for the specified header, or -1 if this header has not been set...
static constexpr int SC_MOVED_PERMANENTLY
Status code (301) indicating that the resource has permanently moved to a new location, and that future references should use a new URI with their requests.
Definition: response.h:338
std::ostream & get_output_stream() override
Returns a std::ostream suitable for writing binary data in the response.
Definitions for input and output filters and related types.
void get_headers(const std::string &name, std::vector< std::string > &headers) const override
Fills the std::vector with all the header values associated with the specified header name...
Definition: response.h:580
void set_status(int sc) override
Sets the status code for this response.
Definition: response.h:591
Provides a convenient implementation of the http_response interface that can be subclassed by develop...
Definition: response.h:545
static constexpr int SC_GATEWAY_TIMEOUT
Status code (504) indicating that the server did not receive a timely response from the upstream serv...
Definition: response.h:527
virtual void add_cookie(const cookie &c)=0
Adds the specified cookie to the response.
static constexpr int SC_REQUESTED_RANGE_NOT_SATISFIABLE
Status code (416) indicating that the server cannot serve the requested byte range.
Definition: response.h:490
static constexpr int SC_NON_AUTHORITATIVE_INFORMATION
Status code (203) indicating that the meta information presented by the client did not originate from...
Definition: response.h:307
static constexpr int SC_NOT_FOUND
Status code (404) indicating that the requested resource is not available.
Definition: response.h:410
string_view get_header(const std::string &name) const override
Return the value for the specified header, or empty string if this header has not been set...
Definition: response.h:578
Defines an object to assist a servlet in sending a response to the client.
Definition: response.h:33
static constexpr int SC_METHOD_NOT_ALLOWED
Status code (405) indicating that the method specified in the Request-Line is not allowed for the res...
Definition: response.h:417
static constexpr int SC_ACCEPTED
Status code (202) indicating that a request was accepted for processing, but was not completed...
Definition: response.h:301
virtual void add_header(const std::string &name, const std::string &value)=0
Adds a response header with the given name and value.
void add_cookie(const cookie &c) override
Adds the specified cookie to the response.
Definition: response.h:571
void add_date_header(const std::string &name, long timeSec) override
Adds a response header with the given name and date-value.
Definition: response.h:573
static constexpr int SC_BAD_GATEWAY
Status code (502) indicating that the HTTP server received an invalid response from a server it consu...
Definition: response.h:515
virtual int get_status() const =0
Get the HTTP status code for this Response.
static constexpr int SC_USE_PROXY
Status code (305) indicating that the requested resource MUST be accessed through the proxy given by ...
Definition: response.h:373
static constexpr int SC_SWITCHING_PROTOCOLS
Status code (101) indicating the server is switching protocols according to Upgrade header...
Definition: response.h:283
static constexpr int SC_NOT_IMPLEMENTED
Status code (501) indicating the HTTP server does not support the functionality needed to fulfill the...
Definition: response.h:509
static constexpr int SC_MOVED_TEMPORARILY
Status code (302) indicating that the resource has temporarily moved to another location, but that future references should still use the original URI to access the resource.
Definition: response.h:346