Skip to content

Commit

Permalink
move the error checks from sslclient.cpp to wsclient.cpp where they b…
Browse files Browse the repository at this point in the history
…elong, so they dont cause excessive data copies or false alarms
  • Loading branch information
braindigitalis committed Sep 30, 2023
1 parent 7cc57af commit 4ab00aa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
22 changes: 0 additions & 22 deletions src/dpp/sslclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,28 +508,6 @@ void ssl_client::read_loop()
case SSL_ERROR_NONE:
/* Data received, add it to the buffer */
if (r > 0) {
const std::string data(server_to_client_buffer, r);
/* Split the data into an array for every line. */
const std::vector<std::string> data_lines = utility::tokenize(data);
/* Get the first line as we always know that's the HTTP response. */
const std::string http_reponse(data_lines[0]);

/* Does the first line begin with a http code? */
if (http_reponse.rfind("HTTP/1.1", 0) != std::string::npos) {
/* Now let's split the first line by every space, meaning we can check the actual HTTP code. */
const std::vector<std::string> line_split_by_space = utility::tokenize(data_lines[0], " ");

/* We need to make sure there's at least 3 elements in line_split_by_space. */
if (line_split_by_space.size() >= 3) {
const int http_code = std::stoi(line_split_by_space[1]);

/* If the http_code isn't 204, 101, or 200, log it. */
if (http_code != 204 && http_code != 101 && http_code != 200) {
log(ll_warning, "Received unhandled code: " + http_reponse);
}
}
}

buffer.append(server_to_client_buffer, r);
if (!this->handle_buffer(buffer)) {
return;
Expand Down
4 changes: 4 additions & 0 deletions src/dpp/wsclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@ bool websocket_client::handle_buffer(std::string &buffer)
}

state = CONNECTED;
} else if (status.size() < 3) {
log(ll_warning, "Malformed HTTP response on websocket");
return false;
} else {
log(ll_warning, "Received unhandled code: " + status[1]);
return false;
}
}
Expand Down

0 comments on commit 4ab00aa

Please sign in to comment.