Git Product home page Git Product logo

via-httplib's People

Contributors

emazv72 avatar kenba avatar louisnayegon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

via-httplib's Issues

native method removed from asio use native_handle

via/comms/connection.hpp:476:66: error: ‘asio::ip::tcp::socket’ has no member named ‘native’

use native_handle. The method 'native' was deprecated earlier and removed in later versions of asio.

Example Client crashes

Platform: windows 10 64-bit
The example client crashes during shutdown because the mutex associated withh http_client is closed earlier when the service goes out of scope. The http_client, declared global, destructs after io_service is destructed.
I'll submit a pull request. Hopefully I fixed the problem correctly.

Remove tx_queue_ from connection class.

The bool connection::send_data(Container packet) method isn't currently used so neither is the tx_queue_ member variable.

Since the Container template variable is only used by send_data and tx_queue_ , this provides an opportunity to remove the Container template variable from the connection class.

How to send streamed reply?

I need to reply to a request with data from a file stream. i.e. I don't want to put the entire response in a buffer for the reply. Is there a way to do this that I am not seeing?

error_handler loops forever after handshake fails

I have a case where using via-httplib as an HTTPS server, the handshake will fail due to unsupported TLS version/cipher specs:

Client Hello:

Secure Sockets Layer
    SSLv2 Record Layer: Client Hello
        [Version: SSL 2.0 (0x0002)]
        Length: 53
        Handshake Message Type: Client Hello (1)
        Version: TLS 1.0 (0x0301)
        Cipher Spec Length: 12
        Session ID Length: 0
        Challenge Length: 32
        Cipher Specs (4 specs)
            Cipher Spec: TLS_RSA_WITH_AES_128_CBC_SHA (0x00002f)
            Cipher Spec: TLS_DHE_RSA_WITH_AES_128_CBC_SHA (0x000033)
            Cipher Spec: TLS_DHE_DSS_WITH_AES_128_CBC_SHA (0x000032)
            Cipher Spec: TLS_DH_anon_WITH_AES_128_CBC_SHA (0x000034)
        Challenge

Handshake Failure:

TLSv1 Record Layer: Alert (Level: Fatal, Description: Handshake Failure)
    Content Type: Alert (21)
    Version: TLS 1.0 (0x0301)
    Length: 2
    Alert Message
        Level: Fatal (2)
        Description: Handshake Failure (40)

I think this failure is expected since the client is attempting to use a deprecated version of SSL/ciphers.

The issue is with how the library handles this. Even though the client does not try to reconnect, the error_handler loops indefinitely:

error_handler
asio.ssl:336130315
error_handler
asio.ssl:336462231
error_handler
asio.ssl:336462231
error_handler
asio.ssl:336462231
error_handler
asio.ssl:336462231
error_handler
asio.ssl:336462231

Is there some call that I am missing?

vs2015 example compile error

Example file : example_https_server.cpp

Error C4996 'boost::asio::basic_socket<Protocol,StreamSocketService>::cancel': By default, this function always fails with operation_not_supported when used on Windows XP, Windows Server 2003, or earlier. Consult documentation for details. Test_via-http c:\users\johndoe\documents\via-httplib\include\via\comms\ssl\ssl_tcp_adaptor.hpp 188

Use thread safe connections and http_connections containers

A part of the fix for issue #11 was to add mutexes to server and http_server to protect connections_ and http_connections_ respectively during concurrent access.

The mutexes provided a quick and simple solution to the issue but std::mutex is notoriously slow.

More efficient, thread-safe (ideally lock free) containers should be used for connections_ and http_connections_ so that the mutexes can be removed.

Add function to filter new connections

Whenever a server accept_handler receives a new client connection it currently accepts it.

The accept_handler provides the first opportunity to determine whether to filter (i.e. accept or reject) a client connection depending upon whether client is in an "allowlist" (a.k.a "whitelist") or a "blocklist" (a.k.a. "blacklist").

The server class should have a new connection filter function pointer, called by the accept_handler and set able by a new method to enable users to filter client connections before performing an SSL handshake. The default should be to accept all incoming connections.

Multithreading and internal router

Hello. I use internal request router in my project, and it works fine. But since I tried to add multithreading, I regularly get error: event_handler error: connection not found.
And sometimes I got SEGFAULT in via::comms::connection constructor:

...
rx_buffer_(new Container(rx_buffer_size_, 0))
...

Here is my code snippet:

using http_server_type = via::http_server<via::comms::tcp_adaptor, std::string, true>;
using MethodHandler = std::function<void(const HttpRequest&, HttpResponse&)>;

class RestServer {
...
  std::unique_ptr<http_server_type> server_;
  std::vector<std::thread> workers_;
  ASIO::io_service io_;
};

RestServer::RestServer(uint16_t port, uint8_t maxThreads)
{
  server_.reset(new http_server_type(io_));
  route("/resource1", resource1_);
  route("/resource2", resource2_);
  ...
  start(port, maxThreads);
}

void RestServer::routeMethod(const std::string& path,
  via::http::request_method::id method,
  MethodHandler handler)
{
  auto& router = server_->request_router();
  router.add_method(method, path, [handler]
    (const via::http::rx_request& req,
     const via::http::Parameters& params,
     const std::string& data,
     std::string& response_body)
    {
       HttpRequest request(params, data);
       HttpResponse response;

       // Call my handler
       handler(request, response);

       via::http::tx_response res(static_cast<via::http::response_status::code>(response.getStatus()));
       res.add_header(via::http::header_field::id::CONTENT_TYPE, response.getContentType());
       response_body = std::move(response.getBody());
       return res;
  });
}

void RestServer::route(const std::string& path, HttpResource& resource)
{
  using namespace via::http::request_method;
  using namespace std::placeholders;
  routeMethod(path, GET, std::bind(&HttpResource::onGet, &resource, _1, _2));
  routeMethod(path, POST, std::bind(&HttpResource::onPost, &resource, _1, _2));
  routeMethod(path, PUT, std::bind(&HttpResource::onPut, &resource, _1, _2));
  routeMethod(path, DELETE, std::bind(&HttpResource::onDelete, &resource, _1, _2));
}

void RestServer::start(uint16_t port, uint8_t maxThreads)
{
  ASIO_ERROR_CODE error(server_->accept_connections(port));
  if (error)
  {
    LOG_ERROR << error.message();
    throw std::runtime_error("Can not start HTTP server");
  }

  for (uint8_t i = 0; i < maxThreads; i++)
    workers_.emplace_back([this] { io_.run(); });
}

So, is it possible to use internal router in multi-threaded server?
Best regards.

Disable multi-threading mutex in single threaded mode

A part of the fix for issue #11 was to add mutexes to server and http_server to protect 'connections_' and http_connections_ respectively during concurrent access.

The mutexes provided a quick and simple solution to the issue but std::mutex is notoriously slow.

The connections_mutex_ and http_connections_mutex_ should not be locked when use_strand == false.

SSL_R_SHORT_READ isn't defined in OpenSSL 1.1.x

The OpenSSL macro SSL_R_SHORT_READ is not defined in the 1.1.x versions of the library.
This macro is tested in the is_disconnect function in ssl_tcp_adaptor.hpp and so it fails to compile when built with 1.1.x versions of the OpenSSL library.

Use async_connect range overload function

The async_connect iterator function is deprecated, see: async_connect
The async_connect range function is preferred, see: async_connect
The comms server shold use the async_connect range function instead of the iterator function.
This should enable the next_socket_ member variable to be removed, since the range function callback contains the newly accepted socket.

Replace SocketAdaptors with asio tcp and ssl sockets.

The HTTP connection class is only used by the tcp_adaptor and ssl_tcp_adaptor which are simply wrappers around the ASIO::ip::tcp::socket and ASIO::ssl::streamASIO::ip::tcp::socket respectively.

The overall design could be simplified by redesigning the connection class to use the asio tcp and ssl sockets directly.

Remove ssl_tcp_adaptor ssl_context() singleton

The ssl_context() singleton in the ssl_tcp_adaptor class prohibits clients and servers in the same application using different ssl_contexts and it limits users to a specific ssl::context::method.

The singleton should be removed and replaced by passing a reference to an ASIO::ssl::context in the ssl_tcp_adaptor class constructor.

This change will ripple through all of the connection, server and associated http_client and http_server classes requiring all their constructors in HTTP_SSL mode to take a reference to an ASIO::ssl::context.

This change will break the API for HTTPS servers and clients.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.