<div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div>Hi.<br><br>There is a big mess with cowboy routes in erlyvideo.<br><br></div>User can access a stream via different http-based protocols. For example if stream is named mtv, urls are:<br>
<br><br></div>/mtv/index.m3u8<br></div>/mtv/manifest.f4m<br></div>/mtv/hls/2012/12/23/14/59.ts<br></div>/mtv/index-123456780-3600.ts<br></div>/mtv/mpegts<br><br></div><div>All of them are mapping to different functions<br>
</div><div><br></div>If user is accessing a dynamic stream, url may be:<br><br></div>/live/user/15/somestream/index.m3u8  - here stream name is "live/user/15/somestream"<br><br></div>So I want to detect handler according to postfix with dynamic length and even with some matching.<br>
<br></div>Currently I do so: I map<br><br></div>[<<"mtv">>, '...'], media_handler<br></div>[<<"live">>, '...', media_handler<br>and then media_handler tries to guess what route is it via dynamic matching:<br>
<br><br></div>route(Segments) -><br></div>  case Segments of<br></div>    [<<"index.m3u8">>] -> ..<br></div>    [<<"index-", TimeSpec/binary>>] -> ...<br></div>    [Part|Rest] -><br>
</div>       route(Rest)<br> <br><br></div>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.<br>
</div><br></div><div>Also I have a problem with clashing /mtv/index.m3u8 and /mtv/index-123456780-3600.ts<br></div><div> that should be routed to different handlers.<br></div><div><br>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:<br>
<br></div>[<<"live">>, Segment1, <<"index.m3u8">>] -><br></div>[<<"live">>, Segment1, Segment2, <<"index.m3u8">>] ->  (and so limit depth of such name).<br>
<br></div><div>So I think that I can pregenerate all possible route matches, but it will not help with clashing names =(<br></div><div><br><br></div>Maybe such router should be made as a cowboy middleware?<br></div>Or I'm missing some cool features inside current router?<br>
<div><div><div><div><div><div><br><br></div></div></div></div></div></div></div>