[erlang-questions] need help with cowboy routing
Tue Jan 29 21:43:48 CET 2013
There is a big mess with cowboy routes in erlyvideo.
User can access a stream via different http-based protocols. For example if
stream is named mtv, urls are:
All of them are mapping to different functions
If user is accessing a dynamic stream, url may be:
/live/user/15/somestream/index.m3u8 - here stream name is
So I want to detect handler according to postfix with dynamic length and
even with some matching.
Currently I do so: I map
[<<"mtv">>, '...'], media_handler
[<<"live">>, '...', media_handler
and then media_handler tries to guess what route is it via dynamic matching:
case Segments of
[<<"index.m3u8">>] -> ..
[<<"index-", TimeSpec/binary>>] -> ...
I think it is a bad idea and think how to rewirte it because this mechanism
makes very difficult to add some other handlers to existing prefix, for
example map "/mtv/mpegts" to mpegts_handler.
Also I have a problem with clashing /mtv/index.m3u8 and
that should be routed to different handlers.
My main idea is to bypass cowboy routing and compile dynamically routing
file with all possible matches for streams with known names and make
several clauses for dynamic streams:
[<<"live">>, Segment1, <<"index.m3u8">>] ->
[<<"live">>, Segment1, Segment2, <<"index.m3u8">>] -> (and so limit depth
of such name).
So I think that I can pregenerate all possible route matches, but it will
not help with clashing names =(
Maybe such router should be made as a cowboy middleware?
Or I'm missing some cool features inside current router?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions