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 privateprocess_and_close_socket()is bypassed. Building withCPPHTTPLIB_KEEPALIVE_PARKINGturns it on for everyServer. - Server:
set_accept_handler()to accept or refuse a connection before any request is read from it, and onSSLServerbefore the TLS handshake (#2700). - WebSocket:
set_websocket_max_message_length()onServerandWebSocketClientsets the largest frame and messageread()accepts per server or client (#2696). It defaults toCPPHTTPLIB_WEBSOCKET_MAX_PAYLOAD_LENGTH.close_status()andclose_reason()onws::WebSocketandWebSocketClientreport the code and reason of the peer's Close onceread()has returnedFail(#2695).WebSocketClientverifies the server certificate with CryptoAPI on Windows, asSSLClientdoes, and getsenable_windows_certificate_verification()to turn it off (#2685).
Behavior changes
- Server:
SSLServerstops waiting for a TLS handshake oncestop()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 promptstop(). - WebSocket:
- A read timeout that elapses inside a frame or between the fragments of a message now returns
Timeout, and the nextread()continues the message. It used to fail the read and close the connection. - WebSocket connections set
TCP_NODELAYby default. DefineCPPHTTPLIB_WEBSOCKET_TCP_NODELAYasfalseto 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.
- A read timeout that elapses inside a frame or between the fragments of a message now returns
- Client: a redirect is followed only to an
http/httpsURL or a reference starting with/(#2684). Any otherLocationis refused, as an unsupported scheme already was.
Security-relevant fixes
- Client: a
Locationof the formhost:portwith 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 thehttp/httpscheck. - 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_urlaccepts an uppercase scheme such asHTTPS://(RFC 3986 3.1), forClient,WebSocketClientand redirects.parse_urltreats://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-Dispositionparameter names are matched case-insensitively (#2698). A part withNAME=was rejected with 400, and one withFILENAME*=was treated as a plain field.
Full Changelog: v0.67.0...v0.68.0