Skip to content

Commit 80be649

Browse files
committed
Fix #961
1 parent 9648f95 commit 80be649

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

httplib.h

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4615,8 +4615,7 @@ inline bool Server::write_response_core(Stream &strm, bool close_connection,
46154615
if (!res.body.empty()) {
46164616
if (!strm.write(res.body)) { ret = false; }
46174617
} else if (res.content_provider_) {
4618-
if (write_content_with_provider(strm, req, res, boundary,
4619-
content_type)) {
4618+
if (write_content_with_provider(strm, req, res, boundary, content_type)) {
46204619
res.content_provider_success_ = true;
46214620
} else {
46224621
res.content_provider_success_ = false;
@@ -5551,8 +5550,8 @@ inline bool ClientImpl::handle_request(Stream &strm, Request &req,
55515550
if (detail::parse_www_authenticate(res, auth, is_proxy)) {
55525551
Request new_req = req;
55535552
new_req.authorization_count_ += 1;
5554-
auto key = is_proxy ? "Proxy-Authorization" : "Authorization";
5555-
new_req.headers.erase(key);
5553+
new_req.headers.erase(is_proxy ? "Proxy-Authorization"
5554+
: "Authorization");
55565555
new_req.headers.insert(detail::make_digest_authentication_header(
55575556
req, auth, new_req.authorization_count_, detail::random_string(10),
55585557
username, password, is_proxy));
@@ -5649,7 +5648,11 @@ inline bool ClientImpl::write_content_with_provider(Stream &strm,
56495648
inline bool ClientImpl::write_request(Stream &strm, Request &req,
56505649
bool close_connection, Error &error) {
56515650
// Prepare additional headers
5652-
if (close_connection) { req.headers.emplace("Connection", "close"); }
5651+
if (close_connection) {
5652+
if (!req.has_header("Connection")) {
5653+
req.headers.emplace("Connection", "close");
5654+
}
5655+
}
56535656

56545657
if (!req.has_header("Host")) {
56555658
if (is_ssl()) {
@@ -5676,8 +5679,10 @@ inline bool ClientImpl::write_request(Stream &strm, Request &req,
56765679
if (req.body.empty()) {
56775680
if (req.content_provider_) {
56785681
if (!req.is_chunked_content_provider_) {
5679-
auto length = std::to_string(req.content_length_);
5680-
req.headers.emplace("Content-Length", length);
5682+
if (!req.has_header("Content-Length")) {
5683+
auto length = std::to_string(req.content_length_);
5684+
req.headers.emplace("Content-Length", length);
5685+
}
56815686
}
56825687
} else {
56835688
if (req.method == "POST" || req.method == "PUT" ||
@@ -5697,24 +5702,32 @@ inline bool ClientImpl::write_request(Stream &strm, Request &req,
56975702
}
56985703

56995704
if (!basic_auth_password_.empty() || !basic_auth_username_.empty()) {
5700-
req.headers.insert(make_basic_authentication_header(
5701-
basic_auth_username_, basic_auth_password_, false));
5705+
if (!req.has_header("Authorization")) {
5706+
req.headers.insert(make_basic_authentication_header(
5707+
basic_auth_username_, basic_auth_password_, false));
5708+
}
57025709
}
57035710

57045711
if (!proxy_basic_auth_username_.empty() &&
57055712
!proxy_basic_auth_password_.empty()) {
5706-
req.headers.insert(make_basic_authentication_header(
5707-
proxy_basic_auth_username_, proxy_basic_auth_password_, true));
5713+
if (!req.has_header("Proxy-Authorization")) {
5714+
req.headers.insert(make_basic_authentication_header(
5715+
proxy_basic_auth_username_, proxy_basic_auth_password_, true));
5716+
}
57085717
}
57095718

57105719
if (!bearer_token_auth_token_.empty()) {
5711-
req.headers.insert(make_bearer_token_authentication_header(
5712-
bearer_token_auth_token_, false));
5720+
if (!req.has_header("Authorization")) {
5721+
req.headers.insert(make_bearer_token_authentication_header(
5722+
bearer_token_auth_token_, false));
5723+
}
57135724
}
57145725

57155726
if (!proxy_bearer_token_auth_token_.empty()) {
5716-
req.headers.insert(make_bearer_token_authentication_header(
5717-
proxy_bearer_token_auth_token_, true));
5727+
if (!req.has_header("Proxy-Authorization")) {
5728+
req.headers.insert(make_bearer_token_authentication_header(
5729+
proxy_bearer_token_auth_token_, true));
5730+
}
57185731
}
57195732

57205733
// Request line and headers
@@ -6687,8 +6700,9 @@ inline ssize_t SSLSocketStream::read(char *ptr, size_t size) {
66876700
auto err = SSL_get_error(ssl_, ret);
66886701
int n = 1000;
66896702
#ifdef _WIN32
6690-
while (--n >= 0 && (err == SSL_ERROR_WANT_READ ||
6691-
err == SSL_ERROR_SYSCALL && WSAGetLastError() == WSAETIMEDOUT)) {
6703+
while (--n >= 0 &&
6704+
(err == SSL_ERROR_WANT_READ ||
6705+
err == SSL_ERROR_SYSCALL && WSAGetLastError() == WSAETIMEDOUT)) {
66926706
#else
66936707
while (--n >= 0 && err == SSL_ERROR_WANT_READ) {
66946708
#endif

0 commit comments

Comments
 (0)