Skip to content

Conversation

@graebm
Copy link
Contributor

@graebm graebm commented Dec 22, 2022

Issue:
If the server rejected a websocket connection, there was no way to see the body of the response. The response body often has useful information explaining why the connection was rejected.

Underlying cause:
The websocket code would close the connection immediately after receiving headers, because that was the simplest way to do things.

Description of changes:
Change the setup callback signature, so that the body can be reported.

The setup code keeps the connection open while receiving a rejection, making a copy of the body, and ultimately reporting it in the setup callback.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@codecov-commenter
Copy link

codecov-commenter commented Dec 22, 2022

Codecov Report

Base: 79.32% // Head: 79.31% // Decreases project coverage by -0.00% ⚠️

Coverage data is based on head (38240d5) compared to base (4e82c1e).
Patch coverage: 90.76% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #409      +/-   ##
==========================================
- Coverage   79.32%   79.31%   -0.01%     
==========================================
  Files          27       27              
  Lines       11761    11759       -2     
==========================================
- Hits         9329     9327       -2     
  Misses       2432     2432              
Impacted Files Coverage Δ
source/websocket_bootstrap.c 90.77% <90.76%> (+6.16%) ⬆️
source/h2_connection.c 82.97% <0.00%> (-1.01%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

int error_code;
struct aws_websocket *websocket;
const int *handshake_response_status;
const struct aws_http_header *handshake_response_header_array;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use const struct *aws_http_headers? Do we really need to have a deep copy of the headers to an array here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually did that, and then reverted it.

There were some downstream uses where the array was being forwarded along, so they would need to deconstruct it back into a raw array to preserve their own APIs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and it's not a "deep copy" it's just one allocation long enough to hold an array.
it's still using the underlying strings stored in the aws_http_headers struct

Co-authored-by: Dengke Tang <dengket@amazon.com>
@graebm graebm merged commit 69b952e into main Dec 23, 2022
@graebm graebm deleted the ws-setup-xtra branch December 23, 2022 18:47
graebm added a commit to awslabs/aws-c-mqtt that referenced this pull request Dec 23, 2022
graebm added a commit to awslabs/aws-c-iot that referenced this pull request Dec 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants