[erlang-questions] need help with cowboy routing

Max Lapshin max.lapshin@REDACTED
Tue Jan 29 21:43:48 CET 2013


Hi.

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:


/mtv/index.m3u8
/mtv/manifest.f4m
/mtv/hls/2012/12/23/14/59.ts
/mtv/index-123456780-3600.ts
/mtv/mpegts

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
"live/user/15/somestream"

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:


route(Segments) ->
  case Segments of
    [<<"index.m3u8">>] -> ..
    [<<"index-", TimeSpec/binary>>] -> ...
    [Part|Rest] ->
       route(Rest)


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
/mtv/index-123456780-3600.ts
 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...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130129/7002e912/attachment.htm>


More information about the erlang-questions mailing list