-
-
Notifications
You must be signed in to change notification settings - Fork 482
Feature: Allow custom headers to be passed via WebSocket #1424
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
base: master
Are you sure you want to change the base?
Feature: Allow custom headers to be passed via WebSocket #1424
Conversation
paullouisageneau
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good overall, thank you. I just have a few comments, the main one being about introducing two maps whereas it seems to me that one would do the job.
| WebSocket::~WebSocket() { PLOG_VERBOSE << "Destroying WebSocket"; } | ||
|
|
||
| void WebSocket::open(const string &url) { | ||
| void WebSocket::open(const string &url, const std::map<string, string> &headers) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick, but since you plan to store the map, you should pass it by value and move it into the WsHandshake() constructor.
| for (const auto& [headerName, headerValue] : mCustomHeaders) { | ||
| out += headerName + ": " + headerValue + "\r\n"; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should at least sanitize headerValue:
| for (const auto& [headerName, headerValue] : mCustomHeaders) { | |
| out += headerName + ": " + headerValue + "\r\n"; | |
| } | |
| for (auto [headerName, headerValue] : mCustomHeaders) { | |
| headerValue.erase(std::remove(headerValue.begin(), headerValue.end(), '\r'), headerValue.end()); | |
| std::replace(headerValue.begin(), headerValue.end(), '\n', ' '); | |
| out += headerName + ": " + headerValue + "\r\n"; | |
| } |
| std::map<string, string> mCustomHeaders; | ||
| std::multimap<string, string> mRequestHeaders; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to use two different maps here? You could use only one multimap.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey ! It's to add support for the websocket server.
But good suggestion. Rather than custom and request we can just rename them to request headers or just headers up to you.
Implement functionality to send and access custom headers during WebSocket handshake and server communication. This enhancement improves authentication and client-server interactions.
Closes: #1342
To Do: