adamdruppe / arsd

This is a collection of modules that I've released over the years. Most of them stand alone, or have just one or two dependencies in here, so you don't have to download this whole repo.
http://arsd-official.dpldocs.info/arsd.html
530 stars 127 forks source link

Websocket: how to pass additional http headers? #275

Closed andre2007 closed 3 years ago

andre2007 commented 3 years ago

I want to use the Websocket class to connect to a websocket server. The server expects that the client sends a bearer token in http header Authorization. As far as I can see, there is no way to pass arbitrary http headers to the WebSocket class. Could you check whether you can add this functionality?

adamdruppe commented 3 years ago

Nope I never implemented that. I did cookies but not extra headers.

Very simple add though.... I just pushed to master, I didn't even test though but if you wanna give it a try and let me know it should be ok.

Config config;
config.additionalHeaders ~= "Authorization: whatever";
auto socket = new WebSocket(Uri("ws://whatever"), config);
/* all the rest the same */
andre2007 commented 3 years ago

Thanks a lot, it works fine.

There is actually an socket error "Socket select error: An invalid argument was supplied" while awaiting a binary message, but this is unrelated to this issue. I will open a separate issue when I can provide you more details.