[erlang-questions] Handling non http in mochiweb

Magnus Klaar magnus.klaar@REDACTED
Thu Aug 18 17:48:41 CEST 2011

2011/8/18 ori brost <oribrost@REDACTED>

> I will describe my exact problem, maybe there are other solutions i
> did not think of.
> Our program provides a websocket service over a port. We wish to allow
> people without a websocket supporting browser to use it so we use a
> flash object to do websocket when the browser can't. In order for this
> to work, 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
> Note that the flash protocol is NOT HTTP based.
> Originally we worked with 843, but we then decided to put out server
> behind an Amazon ELB. Amazon ELB does not allow port forwarding for
> ports below 1024 which are not 80 or 443, so our only choice was to
> implement the flash policy file server in the same port via a patch to
> mochiweb (https://github.com/nivertech/mochiweb/tree/ori_flash_170811).
> We also thought of putting the websocket service behind an haproxy
> instead of ELB, but ELB is better because it is also hardware based
> unlike haproxy which is only software.
> Do you see any other solution for this?
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions


This is a shameless plug for cowboy, putting this aside, I think it you
would end up with a solution similar to this if you were to patch mochiweb
suit this usecase.

I wrote a blog post on getting started using cowboy for non-http protocols
yesterday because of a question on IRC wrt. to finding a reusable
acceptor/handler pool for connection oriented servers. You will find it

Now, you would be able to write a protocol module such as
flash_policy_or_http_protocol that read N bytes from the socket, if they
match an HTTP method, you can call the cowboy_http_protocol:init/4 and
handle it as an HTTP request. If they match what you expect to find at the
head of a flash policy request you can call flash_policy_protocol:init/4.

The only change I anticipate that you would have to make to cowboy itself
would be to add an option for injecting an intial buffer into the
cowboy_http_protocol state to ensure that erlang_decode:packet doesn't start
reading in the middle of the input.

(I failed at the internet, I'm sorry if you receive duplicates of this

MVH Magnus Klaar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110818/9233accc/attachment.htm>

More information about the erlang-questions mailing list