Permalink
Browse files

Merge branch 'websockets' of ssh://192.168.1.6/home/rj/src/playdar-co…

…re/ into websockets
  • Loading branch information...
2 parents 8c3cc2e + c53ca34 commit f94a0d182488458d8c87834d570aab2a35081a46 @RJ committed Jan 10, 2010
Showing with 15 additions and 6 deletions.
  1. +15 −6 src/playdar_http_api.erl
View
@@ -55,8 +55,12 @@ http_req(Req, DocRoot) ->
%MType = content_type(Jsonp /= undefined),
MType = "multipart/x-mixed-replace",
Response = Req:ok({MType, [], chunked}),
- Response:write_chunk("<html><head></head><body>"),
- comet_loop(Response, Jsonp, Cid)
+ case Mode = proplists:get_value("mode", Qs) of
+ "raw" -> ok;
+ _ ->
+ Response:write_chunk("<html><head></head><body>")
+ end,
+ comet_loop(Response, Jsonp, Cid, Mode)
end;
_ ->
@@ -132,17 +136,22 @@ http_req_authed(Req, _DocRoot, Method, Qs, _Auth) ->
Req:not_found()
end.
-comet_loop(Resp, Jsonp, Cid) ->
+comet_loop(Resp, Jsonp, Cid, Mode) ->
receive
{results, Qid, Results} ->
R = {struct, [{<<"method">>, <<"results">>},
{<<"qid">>, Qid},
{<<"results">>, Results}]},
?LOG(info, "Writing COMET response for ~s", [Qid]),
Body = encode_response( R, Jsonp ),
- Resp:write_chunk( io_lib:format("<script type=\"text/javascript\">~s</script>~n",
- [Body]) ),
- comet_loop(Resp, Jsonp, Cid)
+ case Mode of
+ "raw" ->
+ Resp:write_chunk( Body ++ "\n\n" );
+ _ ->
+ Resp:write_chunk( io_lib:format("<script type=\"text/javascript\">~s</script>\n\n",
+ [Body]) )
+ end,
+ comet_loop(Resp, Jsonp, Cid, Mode)
end.
get_results(Req, Qs) ->

0 comments on commit f94a0d1

Please sign in to comment.