@@ -1357,6 +1357,26 @@ inline bool is_connection_error() {
13571357#endif
13581358}
13591359
1360+ inline socket_t create_client_socket (
1361+ const char *host, int port, time_t timeout_sec) {
1362+ return create_socket (
1363+ host, port, [=](socket_t sock, struct addrinfo &ai) -> bool {
1364+ set_nonblocking (sock, true );
1365+
1366+ auto ret = ::connect (sock, ai.ai_addr , static_cast <int >(ai.ai_addrlen ));
1367+ if (ret < 0 ) {
1368+ if (is_connection_error () ||
1369+ !wait_until_socket_is_ready (sock, timeout_sec, 0 )) {
1370+ close_socket (sock);
1371+ return false ;
1372+ }
1373+ }
1374+
1375+ set_nonblocking (sock, false );
1376+ return true ;
1377+ });
1378+ }
1379+
13601380inline std::string get_remote_addr (socket_t sock) {
13611381 struct sockaddr_storage addr;
13621382 socklen_t len = sizeof (addr);
@@ -1542,7 +1562,11 @@ inline uint64_t get_header_value_uint64(const Headers &headers, const char *key,
15421562}
15431563
15441564inline bool read_headers (Stream &strm, Headers &headers) {
1545- static std::regex re (R"( (.+?):\s*(.+?)\s*\r\n)" );
1565+ // Horizontal tab and ' ' are considered whitespace and are ignored when on
1566+ // the left or right side of the header value:
1567+ // - https://stackoverflow.com/questions/50179659/
1568+ // - https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html
1569+ static std::regex re (R"( (.+?):[\t ]*(.+?)[\t ]*\r\n)" );
15461570
15471571 const auto bufsiz = 2048 ;
15481572 char buf[bufsiz];
@@ -3166,22 +3190,7 @@ inline Client::~Client() {}
31663190inline bool Client::is_valid () const { return true ; }
31673191
31683192inline socket_t Client::create_client_socket () const {
3169- return detail::create_socket (
3170- host_.c_str (), port_, [=](socket_t sock, struct addrinfo &ai) -> bool {
3171- detail::set_nonblocking (sock, true );
3172-
3173- auto ret = connect (sock, ai.ai_addr , static_cast <int >(ai.ai_addrlen ));
3174- if (ret < 0 ) {
3175- if (detail::is_connection_error () ||
3176- !detail::wait_until_socket_is_ready (sock, timeout_sec_, 0 )) {
3177- detail::close_socket (sock);
3178- return false ;
3179- }
3180- }
3181-
3182- detail::set_nonblocking (sock, false );
3183- return true ;
3184- });
3193+ return detail::create_client_socket (host_.c_str (), port_, timeout_sec_);
31853194}
31863195
31873196inline bool Client::read_response_line (Stream &strm, Response &res) {
0 commit comments