@@ -56,17 +56,6 @@ using namespace std;
56
56
throw ex; \
57
57
}
58
58
59
- #if OPENSSL_VERSION_NUMBER < 0x30000000L
60
- int BIO_socket_wait (int fd, bool read, time_t timeout)
61
- {
62
- fd_set confds;
63
- FD_ZERO (&confds);
64
- FD_SET (fd, &confds);
65
- timeval tv { timeout, 0 };
66
- return select (fd + 1 , read ? &confds : nullptr , read ? nullptr : &confds, nullptr , &tv);
67
- }
68
- #endif
69
-
70
59
71
60
72
61
Connect::Connect (const string &_url, string _method, int _timeout, const vector<X509Cert> &certs)
@@ -111,6 +100,7 @@ Connect::Connect(const string &_url, string _method, int _timeout, const vector<
111
100
112
101
BIO_set_nbio (d, _timeout > 0 );
113
102
auto start = chrono::high_resolution_clock::now ();
103
+ #if OPENSSL_VERSION_NUMBER < 0x30000000L
114
104
while (BIO_do_connect (d) != 1 )
115
105
{
116
106
if (_timeout == 0 )
@@ -122,6 +112,10 @@ Connect::Connect(const string &_url, string _method, int _timeout, const vector<
122
112
THROW_NETWORKEXCEPTION (" Failed to create connection with host timeout: '%s'" , hostname.c_str ())
123
113
this_thread::sleep_for (chrono::milliseconds (50 ));
124
114
}
115
+ #else
116
+ if (BIO_do_connect_retry (d, timeout, -1 ) < 1 )
117
+ THROW_NETWORKEXCEPTION (" Failed to create connection with host timeout: '%s'" , hostname.c_str ())
118
+ #endif
125
119
126
120
if (usessl > 0 )
127
121
{
@@ -137,7 +131,7 @@ Connect::Connect(const string &_url, string _method, int _timeout, const vector<
137
131
doProxyConnect = false ;
138
132
}
139
133
140
- ssl.reset (SSL_CTX_new (SSLv23_client_method ()), SSL_CTX_free);
134
+ ssl.reset (SSL_CTX_new (TLS_client_method ()), SSL_CTX_free);
141
135
if (!ssl)
142
136
THROW_NETWORKEXCEPTION (" Failed to create ssl connection with host: '%s'" , hostname.c_str ())
143
137
SSL_CTX_set_mode (ssl.get (), SSL_MODE_AUTO_RETRY);
@@ -179,9 +173,19 @@ Connect::Connect(const string &_url, string _method, int _timeout, const vector<
179
173
}
180
174
}
181
175
182
- if (int fd = BIO_get_fd (d, nullptr );
183
- _timeout > 0 && BIO_socket_wait (fd, BIO_should_read (d), _timeout) == -1 )
184
- DEBUG (" select failed" );
176
+ #if OPENSSL_VERSION_NUMBER > 0x30000000L
177
+ if (_timeout > 0 )
178
+ {
179
+ int fd = BIO_get_fd (d, nullptr );
180
+ fd_set confds;
181
+ FD_ZERO (&confds);
182
+ FD_SET (fd, &confds);
183
+ timeval tv { timeout, 0 };
184
+ int read = BIO_should_read (d);
185
+ if (select (fd + 1 , read ? &confds : nullptr , read ? nullptr : &confds, nullptr , &tv) == -1 )
186
+ DEBUG (" select failed" );
187
+ }
188
+ #endif
185
189
186
190
BIO_printf (d, " %s %s HTTP/1.1\r\n " , method.c_str (), path.c_str ());
187
191
addHeader (" Connection" , " close" );
@@ -333,7 +337,8 @@ Connect::Result Connect::exec(initializer_list<pair<string_view,string_view>> he
333
337
334
338
if (!r.isRedirect () || recursive > 3 )
335
339
return r;
336
- string url = r.headers [" Location" ].find (" ://" ) != string::npos ? r.headers [" Location" ] : baseurl + r.headers [" Location" ];
340
+ string location = r.headers .find (" Location" ) == r.headers .cend () ? r.headers [" location" ] : r.headers [" Location" ];
341
+ string url = location.find (" ://" ) != string::npos ? location : baseurl + location;
337
342
Connect c (url, method, timeout);
338
343
c.recursive = recursive + 1 ;
339
344
return c.exec (headers);
0 commit comments