Skip to content

Commit e883094

Browse files
authored
Merge pull request #2 from yhirose/master
Sync repo Oct 30
2 parents 2ad9684 + ff5677a commit e883094

File tree

3 files changed

+48
-18
lines changed

3 files changed

+48
-18
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,27 @@ httplib::Client cli("http://localhost:8080");
365365
httplib::Client cli("https://localhost");
366366
```
367367

368+
### Error code
369+
370+
Here is the list of errors from `Result::error()`.
371+
372+
```c++
373+
enum Error {
374+
Success = 0,
375+
Unknown,
376+
Connection,
377+
BindIPAddress,
378+
Read,
379+
Write,
380+
ExceedRedirectCount,
381+
Canceled,
382+
SSLConnection,
383+
SSLLoadingCerts,
384+
SSLServerVerification,
385+
UnsupportedMultipartBoundaryChars
386+
};
387+
```
388+
368389
### GET with HTTP headers
369390

370391
```c++

httplib.h

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -745,8 +745,11 @@ class Result {
745745
bool operator==(std::nullptr_t) const { return res_ == nullptr; }
746746
bool operator!=(std::nullptr_t) const { return res_ != nullptr; }
747747
const Response &value() const { return *res_; }
748+
Response &value() { return *res_; }
748749
const Response &operator*() const { return *res_; }
750+
Response &operator*() { return *res_; }
749751
const Response *operator->() const { return res_.get(); }
752+
Response *operator->() { return res_.get(); }
750753
Error error() const { return err_; }
751754

752755
private:
@@ -3164,7 +3167,7 @@ get_range_offset_and_length(const Request &req, size_t content_length,
31643167
auto slen = static_cast<ssize_t>(content_length);
31653168

31663169
if (r.first == -1) {
3167-
r.first = std::max(static_cast<ssize_t>(0), slen - r.second);
3170+
r.first = (std::max)(static_cast<ssize_t>(0), slen - r.second);
31683171
r.second = slen - 1;
31693172
}
31703173

@@ -5737,22 +5740,7 @@ inline SSLSocketStream::SSLSocketStream(socket_t sock, SSL *ssl,
57375740
read_timeout_usec_(read_timeout_usec),
57385741
write_timeout_sec_(write_timeout_sec),
57395742
write_timeout_usec_(write_timeout_usec) {
5740-
{
5741-
timeval tv;
5742-
tv.tv_sec = static_cast<long>(read_timeout_sec);
5743-
tv.tv_usec = static_cast<decltype(tv.tv_usec)>(read_timeout_usec);
5744-
5745-
setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, reinterpret_cast<char *>(&tv),
5746-
sizeof(tv));
5747-
}
5748-
{
5749-
timeval tv;
5750-
tv.tv_sec = static_cast<long>(write_timeout_sec);
5751-
tv.tv_usec = static_cast<decltype(tv.tv_usec)>(write_timeout_usec);
5752-
5753-
setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, reinterpret_cast<char *>(&tv),
5754-
sizeof(tv));
5755-
}
5743+
SSL_clear_mode(ssl, SSL_MODE_AUTO_RETRY);
57565744
}
57575745

57585746
inline SSLSocketStream::~SSLSocketStream() {}
@@ -5767,8 +5755,27 @@ inline bool SSLSocketStream::is_writable() const {
57675755
}
57685756

57695757
inline ssize_t SSLSocketStream::read(char *ptr, size_t size) {
5770-
if (SSL_pending(ssl_) > 0 || is_readable()) {
5758+
if (SSL_pending(ssl_) > 0) {
57715759
return SSL_read(ssl_, ptr, static_cast<int>(size));
5760+
} else if (is_readable()) {
5761+
auto ret = SSL_read(ssl_, ptr, static_cast<int>(size));
5762+
if (ret < 0) {
5763+
auto err = SSL_get_error(ssl_, ret);
5764+
while (err == SSL_ERROR_WANT_READ) {
5765+
if (SSL_pending(ssl_) > 0) {
5766+
return SSL_read(ssl_, ptr, static_cast<int>(size));
5767+
} else if (is_readable()) {
5768+
ret = SSL_read(ssl_, ptr, static_cast<int>(size));
5769+
if (ret >= 0) {
5770+
return ret;
5771+
}
5772+
err = SSL_get_error(ssl_, ret);
5773+
} else {
5774+
return -1;
5775+
}
5776+
}
5777+
}
5778+
return ret;
57725779
}
57735780
return -1;
57745781
}

test/test.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3299,6 +3299,7 @@ TEST(SSLClientServerTest, ClientCertPresent) {
32993299
t.join();
33003300
}
33013301

3302+
#if !defined(_WIN32) || defined(OPENSSL_USE_APPLINK)
33023303
TEST(SSLClientServerTest, MemoryClientCertPresent) {
33033304
X509 *server_cert;
33043305
EVP_PKEY *server_private_key;
@@ -3374,6 +3375,7 @@ TEST(SSLClientServerTest, MemoryClientCertPresent) {
33743375

33753376
t.join();
33763377
}
3378+
#endif
33773379

33783380
TEST(SSLClientServerTest, ClientCertMissing) {
33793381
SSLServer svr(SERVER_CERT_FILE, SERVER_PRIVATE_KEY_FILE, CLIENT_CA_CERT_FILE,

0 commit comments

Comments
 (0)