Skip to content

v0.68.0

Latest

Choose a tag to compare

@yhirose yhirose released this 28 Nov 14:33

What's Changed

New features

  • Server: keep-alive parking, set_keep_alive_parking() (#2686). Experimental and off by default. A connection waiting for its next request is parked on an event loop (epoll, kqueue or poll) instead of holding a worker thread, so connections beyond the thread count are no longer starved. Handlers, content providers and WebSocket keep their blocking API. With it on, consecutive requests on a connection may run on different threads, and a subclass that overrides the private process_and_close_socket() is bypassed. Building with CPPHTTPLIB_KEEPALIVE_PARKING turns it on for every Server.
  • Server: set_accept_handler() to accept or refuse a connection before any request is read from it, and on SSLServer before the TLS handshake (#2700).
  • WebSocket:
    • set_websocket_max_message_length() on Server and WebSocketClient sets the largest frame and message read() accepts per server or client (#2696). It defaults to CPPHTTPLIB_WEBSOCKET_MAX_PAYLOAD_LENGTH.
    • close_status() and close_reason() on ws::WebSocket and WebSocketClient report the code and reason of the peer's Close once read() has returned Fail (#2695).
    • WebSocketClient verifies the server certificate with CryptoAPI on Windows, as SSLClient does, and gets enable_windows_certificate_verification() to turn it off (#2685).

Behavior changes

  • Server: SSLServer stops waiting for a TLS handshake once stop() is called (#2689). A connection that was waiting for a worker at that point is now closed with its handshake cut short, where v0.67.0 still served it. This favors a prompt stop().
  • WebSocket:
    • A read timeout that elapses inside a frame or between the fragments of a message now returns Timeout, and the next read() continues the message. It used to fail the read and close the connection.
    • WebSocket connections set TCP_NODELAY by default. Define CPPHTTPLIB_WEBSOCKET_TCP_NODELAY as false to keep Nagle's algorithm.
    • read() sends a Close frame with a status (1002 Protocol Error or 1009 Message Too Big) before failing on any protocol error or an oversized message (#2694). The peer used to see the connection drop without a reason.
  • Client: a redirect is followed only to an http/https URL or a reference starting with / (#2684). Any other Location is refused, as an unsupported scheme already was.

Security-relevant fixes

  • Client: a Location of the form host:port with no scheme is no longer followed as a redirect to that host and port (#2684). It came out of parsing with an empty scheme and slipped past the http/https check.
  • WebSocket: a frame write that fails partway marks the connection closed. Its header had already announced the whole payload, so later writes were read by the peer as the rest of that frame.

Bug fixes

  • parse_url accepts an uppercase scheme such as HTTPS:// (RFC 3986 3.1), for Client, WebSocketClient and redirects.
  • parse_url treats :// as a scheme separator only before the path, so a redirect to a path whose query holds a URL, such as /login?next=https://example.com/, is followed (#2701).
  • Multipart: Content-Disposition parameter names are matched case-insensitively (#2698). A part with NAME= was rejected with 400, and one with FILENAME*= was treated as a plain field.

Full Changelog: v0.67.0...v0.68.0