LCOV - code coverage report
Current view: top level - zeroeq/http - response.h (source / functions) Hit Total Coverage
Test: ZeroEQ Lines: 13 13 100.0 %
Date: 2017-12-01 01:44:57 Functions: 6 6 100.0 %

          Line data    Source code
       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             : {
      15             : /** HTTP headers which can be used in a Response. */
      16             : enum class Header
      17             : {
      18             :     ALLOW,
      19             :     CONTENT_TYPE,
      20             :     LAST_MODIFIED,
      21             :     LOCATION,
      22             :     RETRY_AFTER
      23             : };
      24             : 
      25             : /** HTTP codes to be used in a Response. */
      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             : 
      53             : /**
      54             :  * Response to an HTTP Request.
      55             :  */
      56         832 : struct Response
      57             : {
      58             :     /** HTTP return code. */
      59             :     Code code;
      60             : 
      61             :     /** Payload to return in a format specified in CONTENT_TYPE header. */
      62             :     std::string body;
      63             : 
      64             :     /** HTTP message headers. */
      65             :     std::map<Header, std::string> headers;
      66             : 
      67             :     /** Construct a Response with a given return code and payload. */
      68         173 :     Response(const Code code_ = Code::OK,
      69             :              const std::string& body_ = std::string())
      70         173 :         : code{code_}
      71         173 :         , body{body_}
      72             :     {
      73         173 :     }
      74             : 
      75             :     /** Construct a Response with a given code, payload and content type. */
      76          22 :     Response(const Code code_, const std::string& body_,
      77             :              const std::string& contentType)
      78          22 :         : code{code_}
      79             :         , body{body_}
      80          22 :         , headers{{Header::CONTENT_TYPE, contentType}}
      81             :     {
      82          22 :     }
      83             : 
      84             :     /** Construct a Response with a given code, payload and map of headers. */
      85          13 :     Response(const Code code_, const std::string& body_,
      86             :              std::map<Header, std::string> headers_)
      87          13 :         : code{code_}
      88             :         , body{body_}
      89          13 :         , headers{{std::move(headers_)}}
      90             :     {
      91          13 :     }
      92             : };
      93             : }
      94             : }
      95             : 
      96             : #endif

Generated by: LCOV version 1.11