basho/webmachine — pull request #175 by choptastic (2013-11-08 21:47:14+00:00)
Title: Expose the actual socket with wrq:socket

This adds wrq:socket/1, which can be used if an app happens to need access to the socket itself, without having to include webmachine records, and without having to message around with element/2.

Originally, I though sock/1 was what I needed, but it turns out to only return the IP address. So if there's another way to do this, that'd be great.

In my case, I'm adding a websocket layer to simple bridge for backends that don't support websockets, and in order to do so, I need to hijack the socket. While I have it working with a combination of element/2 on the Webmachine Req record, then calling webmachine_request:socket/1 on it, I'd much rather not rely on the record element positioning hack and go with something more "sanctioned".

That said, if what I'm looking for is already available without `element/2` hacks or including the webmachine .hrl files, in my app, I'd love to hear it. But I figured since this was so quick to implement, that I might as well put in a PR.

I will note that this patch, in its current form, does work for adding a websocket layer onto webmachine with simple bridge (which I'll be putting out publicly in the next few days for folks to kick the tires).

Thanks, and have a great one!