Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move the error checks from sslclient.cpp to wsclient.cpp where they belong, so they dont cause excessive data copies or false alarms #902

Merged
merged 2 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
braindigitalis marked this conversation as resolved.
Show resolved Hide resolved
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
Loading