[erlang-questions] need help with cowboy routing

Michael Truog <>
Tue Jan 29 22:32:05 CET 2013


You could use my trie data structure with list-of-integers keys (and module/function values) to do a lookup with patterns like:
/live/user/*/*/index.m3u8

If that is what you are looking for.  You would just use trie:find_match/2 and then perhaps trie:pattern_parse/2 if you wanted the individual dynamic values.  The trie:find_match/2 function is used within cpg within CloudI to handle request routing to processes, for the same purpose.

The code is here https://github.com/okeuday/trie

On 01/29/2013 12:43 PM, Max Lapshin wrote:
> 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?
>
>
>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130129/508904fa/attachment.html>


More information about the erlang-questions mailing list