ZeroEQ  0.9.0
ZeroEQ - Zero Event Queue
response.h
1 /* Copyright (c) 2017, EPFL/Blue Brain Project
2  * Pawel Podhajski <pawel.podhajski@epfl.ch>
3  */
4 
5 #ifndef ZEROEQ_HTTP_RESPONSE_H
6 #define ZEROEQ_HTTP_RESPONSE_H
7 
8 #include <map> // member
9 #include <string> // member
10 
11 namespace zeroeq
12 {
13 namespace http
14 {
16 enum class Header
17 {
18  ALLOW,
19  CONTENT_TYPE,
20  LAST_MODIFIED,
21  LOCATION,
22  RETRY_AFTER
23 };
24 
26 enum Code
27 {
28  OK = 200,
29  CREATED = 201,
30  ACCEPTED = 202,
31  NO_CONTENT = 204,
32  PARTIAL_CONTENT = 206,
33  MULTIPLE_CHOICES = 300,
34  MOVED_PERMANENTLY = 301,
35  MOVED_TEMPORARILY = 302,
36  NOT_MODIFIED = 304,
37  BAD_REQUEST = 400,
38  UNAUTHORIZED = 401,
39  FORBIDDEN = 403,
40  NOT_FOUND = 404,
41  NOT_SUPPORTED = 405,
42  NOT_ACCEPTABLE = 406,
43  REQUEST_TIMEOUT = 408,
44  PRECONDITION_FAILED = 412,
45  UNSATISFIABLE_RANGE = 416,
46  INTERNAL_SERVER_ERROR = 500,
47  NOT_IMPLEMENTED = 501,
48  BAD_GATEWAY = 502,
49  SERVICE_UNAVAILABLE = 503,
50  SPACE_UNAVAILABLE = 507
51 };
52 
56 struct Response
57 {
60 
62  std::string body;
63 
65  std::map<Header, std::string> headers;
66 
68  Response(const Code code_ = Code::OK,
69  const std::string& body_ = std::string())
70  : code{code_}
71  , body{body_}
72  {
73  }
74 
76  Response(const Code code_, const std::string& body_,
77  const std::string& contentType)
78  : code{code_}
79  , body{body_}
80  , headers{{Header::CONTENT_TYPE, contentType}}
81  {
82  }
83 
85  Response(const Code code_, const std::string& body_,
86  std::map<Header, std::string> headers_)
87  : code{code_}
88  , body{body_}
89  , headers{{std::move(headers_)}}
90  {
91  }
92 };
93 }
94 }
95 
96 #endif
std::string body
Payload to return in a format specified in CONTENT_TYPE header.
Definition: response.h:62
Response(const Code code_, const std::string &body_, std::map< Header, std::string > headers_)
Construct a Response with a given code, payload and map of headers.
Definition: response.h:85
Code
HTTP codes to be used in a Response.
Definition: response.h:26
Response to an HTTP Request.
Definition: response.h:56
Header
HTTP headers which can be used in a Response.
Definition: response.h:16
Response(const Code code_=Code::OK, const std::string &body_=std::string())
Construct a Response with a given return code and payload.
Definition: response.h:68
Code code
HTTP return code.
Definition: response.h:59
std::map< Header, std::string > headers
HTTP message headers.
Definition: response.h:65
Publish-subscribe and request-reply.
Definition: client.h:10
Response(const Code code_, const std::string &body_, const std::string &contentType)
Construct a Response with a given code, payload and content type.
Definition: response.h:76