ws-rs
ws-rs copied to clipboard
Send headers with websocket connection
I'm trying to send custom headers with the websocket connection but I can't figure out how. There was a previous issue that mentioned this (#43), however, all the links given in that issue are dead. Can someone show me how to send headers to an open websocket connection?
For client handler overwrite build_request:
fn build_request(&mut self, url: &url::Url) -> ws::Result<Request> { let mut req = Request::from_url(url)?;
req.headers_mut().push(("TheHeader".into(), "That's it".into()));
Ok(req)
}
For server I think you can do same thing inside on_open (Should be checked though):
fn on_open(&mut self, hs: Handshake) -> ws::Result<()> { hs.req.headers_mut().push(("TheHeader".into(), "That's it".into())); }