Permalink
Browse files

auto-skip streams that have an html content type, add a stream data t…

…imeout
  • Loading branch information...
1 parent ba5a95f commit 613800290416c63093625b4778d0726b1d243b53 @RJ committed Nov 25, 2009
Showing with 24 additions and 9 deletions.
  1. +24 −9 playdar_modules/basic_readers/src/http_reader.erl
@@ -4,6 +4,7 @@
-include_lib("kernel/include/file.hrl").
-define(HTTP_HEADERS_TIMEOUT, 5000).
+-define(HTTP_STREAM_TIMEOUT, 10000).
-export([start_link/3, reader_protocols/0]).
@@ -28,15 +29,25 @@ run({struct, A}, Pid, Ref) ->
{http, {Id, stream_start, Headers}} ->
?LOG(info, "Serving stream: ~s", [Url]),
% snag the content-length and content-type headers:
- Headers1 = [ { "content-type",
- proplists:get_value("content-type", Headers,
- "binary/unknown-not-specified")} ],
- Headers2 = case proplists:get_value("content-length", Headers) of
- undefined -> Headers1;
- Len -> [ {"content-length", Len} | Headers1 ]
- end,
- Pid ! {Ref, headers, Headers2},
- start_streaming(Id, Pid, Ref);
+ ContentType = proplists:get_value("content-type", Headers,
+ "binary/unknown-not-specified"),
+ ContentLength = proplists:get_value("content-length", Headers),
+ % some results from web indexes to audio files have expired and
+ % just give you an html response that says bugger off:
+ case string:str(ContentType, "text/html") of
+ 0 ->
+ Headers1 = [ { "content-type", ContentType } ],
+ Headers2 = case ContentLength of
+ undefined -> Headers1;
+ Len -> [ {"content-length", Len} | Headers1 ]
+ end,
+ ?LOG(info, "starting stream, type: ~s size: ~s", [ContentType, ContentLength]),
+ Pid ! {Ref, headers, Headers2},
+ start_streaming(Id, Pid, Ref);
+ _ ->
+ ?LOG(warning, "Got content type of ~s - aborting, probably failed.", [ContentType]),
+ Pid ! {Ref, error, "Suspicious content type header"}
+ end;
{http, {Id, error, Reason}} ->
?LOG(warning, "HTTP req failed for ~s",[Url]),
@@ -59,5 +70,9 @@ start_streaming(Id, Pid, Ref) ->
{http, {Id, stream_end, _Headers}} ->
Pid ! {Ref, eof}
+
+ after ?HTTP_STREAM_TIMEOUT ->
+ ?LOG(warning, "Timeout receiving stream", []),
+ Pid ! {Ref, error, timeout}
end.

0 comments on commit 6138002

Please sign in to comment.