non-http in mochiweb
I am using mochiweb for a server that may also get a TCP connction to which the client sends a simple string (without a newline, the s开发者_StackOverflowtring is not http). Mochiweb uses HTTP sockets and therefore fails to detect this (i dont even get http_error
that i can easily get in mochiweb). How can I solve this? Ideally I wish to change mochiweb code to do setopt({packet, http_or_raw})
but this kind of thing does not exist. How would you recommend handling this? my current idea was to modify mochiweb and use erlang:decode_packet
, is there a better approach?
EDIT:
More info. Our server is a websocket service. We wish to allow people without a ws supporting browser to use it so we use a flash object to do websocket when the browser can't. The flash object needs to get a flash policy file. Flash forces the file to be in one of two places: - port 843 (flash hard coded) - the port of the ws service The flash protocol is NOT HTTP based. Amazon ELB does not allow port forwarding for most ports below 1024, so we implemented the flash server in the same port via a patch to mochiweb (https://github.com/nivertech/mochiweb/tree/ori_flash_170811).
Any advice?
mochiweb isn't designed to handle this use case, if it doesn't look like HTTP then the connection is closed and it gets discarded. You would have to go around mochiweb_http for this purpose. I'd suggest using an alternate port, or making it look like HTTP.
If I really wanted to do what you say you want to do, I would copy mochiweb_http.erl to some other name (e.g. sometimes_not_http.erl) and make the appropriate changes to loop/2 and request/2… then instead of adding mochiweb_http to your supervisor you'd add sometimes_not_http. It is not necessary or recommended to make modifications to mochiweb in-place.
精彩评论