Skip to content

Commit

Permalink
Change the message task to the new error interface
Browse files Browse the repository at this point in the history
  • Loading branch information
durner committed Mar 5, 2024
1 parent 2aaf5fb commit da1fcdc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
4 changes: 4 additions & 0 deletions include/network/http_response.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ struct HttpResponse {
default: return "UNKNOWN";
}
}
/// Check for successful operation 2xx operations
static constexpr auto checkSuccess(const Code& code) {
return (code == Code::OK_200 || code == Code::CREATED_201 || code == Code::NO_CONTENT_204 || code == Code::PARTIAL_CONTENT_206);
}
/// Deserialize the response
[[nodiscard]] static HttpResponse deserialize(std::string_view data);
};
Expand Down
10 changes: 8 additions & 2 deletions src/network/http_message.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "network/http_message.hpp"
#include "network/http_response.hpp"
#include "network/message_result.hpp"
#include "utils/data_vector.hpp"
#include "utils/timer.hpp"
Expand Down Expand Up @@ -98,8 +99,13 @@ MessageState HTTPMessage::execute(IOUringSocket& socket)
socket.disconnect(request->fd, originalMessage->hostname, originalMessage->port, &tcpSettings, static_cast<uint64_t>(sendBufferOffset + receiveBufferOffset));
originalMessage->result.size = info->length;
originalMessage->result.offset = info->headerLength;
state = MessageState::Finished;
return MessageState::Finished;
if (HttpResponse::checkSuccess(info->response.code)) {
state = MessageState::Finished;
} else {
originalMessage->result.failureCode |= static_cast<uint16_t>(MessageFailureCode::HTTP);
state = MessageState::Aborted;
}
return state;
}
} catch (exception&) {
originalMessage->result.failureCode |= static_cast<uint16_t>(MessageFailureCode::HTTP);
Expand Down
9 changes: 8 additions & 1 deletion src/network/https_message.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#include "network/https_message.hpp"
#include "network/http_response.hpp"
#include "network/message_result.hpp"
#include "utils/data_vector.hpp"
#include "utils/timer.hpp"
#include <cassert>
#include <memory>
#include <utility>
#include <openssl/bio.h>
#include <openssl/crypto.h>
#include <openssl/err.h>
#include <openssl/ssl.h>
#include <utility>
//---------------------------------------------------------------------------
// AnyBlob - Universal Cloud Object Storage Library
// Dominik Durner, 2023
Expand Down Expand Up @@ -104,6 +105,12 @@ MessageState HTTPSMessage::execute(IOUringSocket& socket)
if (HttpHelper::finished(receive.data(), static_cast<uint64_t>(receiveBufferOffset), info)) {
originalMessage->result.size = info->length;
originalMessage->result.offset = info->headerLength;
if (HttpResponse::checkSuccess(info->response.code)) {
state = MessageState::TLSShutdown;
} else {
originalMessage->result.failureCode |= static_cast<uint16_t>(MessageFailureCode::HTTP);
reset(socket, true);
}
state = MessageState::TLSShutdown;
return execute(socket);
} else {
Expand Down

0 comments on commit da1fcdc

Please sign in to comment.