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

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2016-2017, Human Brain Project
       3             :  *                          Stefan.Eilemann@epfl.ch
       4             :  *                          Daniel.Nachbaur@epfl.ch
       5             :  *                          Raphael.Dumusc@epfl.ch
       6             :  */
       7             : 
       8             : #ifndef ZEROEQ_HTTP_REQUESTHANDLER_H
       9             : #define ZEROEQ_HTTP_REQUESTHANDLER_H
      10             : 
      11             : #include <zeroeq/http/request.h>  // member
      12             : #include <zeroeq/http/response.h> // member
      13             : 
      14             : #include <zeroeq/detail/context.h>
      15             : 
      16             : #include <boost/network/protocol/http/server.hpp>
      17             : #include <future>
      18             : 
      19             : namespace zeroeq
      20             : {
      21             : namespace http
      22             : {
      23             : class RequestHandler;
      24             : typedef boost::network::http::server<RequestHandler> HTTPServer;
      25             : 
      26             : // HTTP headers for CORS responses
      27             : enum class CorsResponseHeader
      28             : {
      29             :     access_control_allow_headers,
      30             :     access_control_allow_methods,
      31             :     access_control_allow_origin
      32             : };
      33             : 
      34             : // Contains in/out values for an HTTP request to exchange information between
      35             : // cppnetlib and zeroeq::http::Server
      36         416 : struct Message
      37             : {
      38             :     // input from cppnetlib and updated in server.cpp
      39             :     Request request;
      40             : 
      41             :     // input from cppnetlib, internal for CORS requests
      42             :     std::string origin;
      43             :     std::string accessControlRequestHeaders;
      44             :     Method accessControlRequestMethod = Method::ALL;
      45             : 
      46             :     // output from zeroeq::http::Server
      47             :     std::future<Response> response;
      48             : 
      49             :     // output from zeroeq::http::Server, internal for CORS responses
      50             :     std::map<CorsResponseHeader, std::string> corsResponseHeaders;
      51             : };
      52             : 
      53             : // The handler class called for each incoming HTTP request from cppnetlib
      54             : class RequestHandler
      55             : {
      56             : public:
      57             :     /**
      58             :      * @param zmqURL URL to inproc socket for communication between cppnetlib
      59             :      *               thread and zeroeq::http::Server thread
      60             :      */
      61             :     RequestHandler(const std::string& zmqURL);
      62             : 
      63             :     ~RequestHandler();
      64             : 
      65             :     /** Callback for each request from cppnetlib server. */
      66             :     void operator()(const HTTPServer::request& request,
      67             :                     HTTPServer::connection_ptr connection);
      68             : 
      69             : private:
      70             :     zmq::ContextPtr _context;
      71             :     void* _socket;
      72             : };
      73             : }
      74             : }
      75             : 
      76             : #endif

Generated by: LCOV version 1.11