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 (#902)
  • Loading branch information
braindigitalis authored Sep 30, 2023
1 parent 7cc57af commit cca47cf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 23 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
6 changes: 5 additions & 1 deletion 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 {
} else if (status.size() < 3) {
log(ll_warning, "Malformed HTTP response on websocket");
return false;
} else if (status[1] != "200" && status[1] != "204") {
log(ll_warning, "Received unhandled code: " + status[1]);
return false;
}
}
Expand Down

0 comments on commit cca47cf

Please sign in to comment.