0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 01:21:03 +01:00

SERVER-34228 Make HTTP handling check status code

This commit is contained in:
Mark Benvenuto 2018-05-01 13:37:31 -04:00
parent 930e6de854
commit 720d7a3db3
3 changed files with 37 additions and 0 deletions

View File

@ -104,6 +104,7 @@ class FreeMonHandler(http.server.BaseHTTPRequestHandler):
self.send_response(http.HTTPStatus.INTERNAL_SERVER_ERROR)
self.send_header("content-type", "application/octet-stream")
self.end_headers()
self.wfile.write("Internal Error of some sort.".encode())
return
if fault_type == FAULT_INVALID_REGISTER:

View File

@ -210,6 +210,22 @@ private:
return;
}
long statusCode;
result = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &statusCode);
if (result != CURLE_OK) {
shared_promise.setError({ErrorCodes::OperationFailed,
str::stream() << "Unexpected error retrieving response: "
<< curl_easy_strerror(result)});
return;
}
if (statusCode != 200) {
shared_promise.setError(Status(
ErrorCodes::OperationFailed,
str::stream() << "Unexpected http status code from server: " << statusCode));
return;
}
auto d = dataBuilder.getCursor();
shared_promise.emplaceValue(std::vector<uint8_t>(d.data(), d.data() + d.length()));
} catch (...) {

View File

@ -257,6 +257,26 @@ private:
return;
}
DWORD statusCode = 0;
DWORD statusCodeLength = sizeof(statusCode);
if (!WinHttpQueryHeaders(request,
WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER,
WINHTTP_HEADER_NAME_BY_INDEX,
&statusCode,
&statusCodeLength,
WINHTTP_NO_HEADER_INDEX)) {
setError("Error querying status from server");
return;
}
if (statusCode != 200) {
shared_promise.setError(
Status(ErrorCodes::OperationFailed,
str::stream() << "Unexpected http status code from server: " << statusCode));
return;
}
// Marshal response into vector.
std::vector<uint8_t> ret;
auto sz = ret.size();