@@ -1357,6 +1357,26 @@ inline bool is_connection_error() {
1357
1357
#endif
1358
1358
}
1359
1359
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
+
1360
1380
inline std::string get_remote_addr (socket_t sock) {
1361
1381
struct sockaddr_storage addr;
1362
1382
socklen_t len = sizeof (addr);
@@ -1542,7 +1562,11 @@ inline uint64_t get_header_value_uint64(const Headers &headers, const char *key,
1542
1562
}
1543
1563
1544
1564
inline 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)" );
1546
1570
1547
1571
const auto bufsiz = 2048 ;
1548
1572
char buf[bufsiz];
@@ -3166,22 +3190,7 @@ inline Client::~Client() {}
3166
3190
inline bool Client::is_valid () const { return true ; }
3167
3191
3168
3192
inline 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_);
3185
3194
}
3186
3195
3187
3196
inline bool Client::read_response_line (Stream &strm, Response &res) {
0 commit comments