-
Notifications
You must be signed in to change notification settings - Fork 617
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
Passing Headers to WebSocketClient.connect() #1282
Conversation
ruthvik seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
We can use a hyper::Request to which we can insert headers and pass it in connect_async() to connect from the client. Is adding an extra parameter for headers: for every function that is calling connect() or connect_with_server() better , or is making a separate function for connecting with headers better? |
Hi @ruthvik125 |
@@ -359,6 +364,7 @@ impl WebSocketClient { | |||
#[staticmethod] | |||
fn connect( | |||
url: String, | |||
headers:Vec<(&str,&str)>, |
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.
You'll need to take a Vec<(String, String)>
because having lifetimes will be problematic in the Python API. And you want to store these headers in the WebsocketInnerClient
so that they can be re-used in case of a reconnect.
@@ -86,7 +86,11 @@ impl WebSocketClientInner { | |||
/// Connects with the server creating a tokio-tungstenite websocket stream. | |||
#[inline] | |||
pub async fn connect_with_server(url: &str) -> Result<(MessageWriter, MessageReader), Error> { |
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.
You want to pass a clone of the stored Vec<(String, String)>
here. Then consume and add the key value pairs to the request.
We also need to run the pre-commit checks:
or
Many thanks! |
Pull Request
For issue #1236
-> Passing a hyper::Request to which headers can be inserted ,instead of a url ,in connect_async()
Type Of Change