Skip to content

Commit

Permalink
Add a lot of todos
Browse files Browse the repository at this point in the history
  • Loading branch information
essen committed Aug 10, 2016
1 parent ae0dd61 commit 3a05768
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/cowboy.erl
Expand Up @@ -19,6 +19,7 @@
-export([stop_listener/1]).
-export([set_env/3]).

%% @todo Detailed opts.
-type opts() :: map().
-export_type([opts/0]).

Expand Down
17 changes: 17 additions & 0 deletions src/cowboy_http.erl
Expand Up @@ -270,6 +270,7 @@ after_parse({request, Req=#{streamid := StreamID, headers := Headers, version :=
error_logger:error_msg("Exception occurred in ~s:init(~p, ~p, ~p) "
"with reason ~p:~p.",
[Handler, StreamID, Req, Opts, Class, Reason]),
%% @todo Bad value returned here. Crashes.
ok
%% @todo Status code.
% stream_reset(State, StreamID, {internal_error, {Class, Reason},
Expand All @@ -287,6 +288,7 @@ after_parse({data, StreamID, IsFin, Data, State=#state{handler=Handler,
catch Class:Reason ->
error_logger:error_msg("Exception occurred in ~s:data(~p, ~p, ~p, ~p) with reason ~p:~p.",
[Handler, StreamID, IsFin, Data, StreamState0, Class, Reason]),
%% @todo Bad value returned here. Crashes.
ok
%% @todo
% stream_reset(State, StreamID, {internal_error, {Class, Reason},
Expand Down Expand Up @@ -618,6 +620,9 @@ request(Buffer, State0=#state{ref=Ref, transport=Transport, peer=Peer, in_stream
scheme => Scheme,
host => Host,
port => Port,

%% @todo So the path component needs to be normalized.

path => Path,
qs => Qs,
version => Version,
Expand Down Expand Up @@ -735,6 +740,11 @@ parse_body(Buffer, State=#state{in_streamid=StreamID, in_state=

%% Message handling.

%% @todo There is a difference in behavior between HTTP/1.1 and HTTP/2
%% when an error or crash occurs after sending a 500 response. In HTTP/2
%% the error will be printed, in HTTP/1.1 the error will be ignored.
%% This is due to HTTP/1.1 disabling streams differently after both
%% requests and responses have been sent.
down(State=#state{children=Children0}, Pid, Msg) ->
case lists:keytake(Pid, 1, Children0) of
{value, {_, undefined, _}, Children} ->
Expand Down Expand Up @@ -837,8 +847,12 @@ commands(State0=#state{socket=Socket, transport=Transport, streams=Streams}, Str
%% Send a response body chunk.
%%
%% @todo WINDOW_UPDATE stuff require us to buffer some data.
%% @todo We probably want to allow Data to be the {sendfile, ...} tuple also.
commands(State=#state{socket=Socket, transport=Transport, streams=Streams}, StreamID,
[{data, IsFin, Data}|Tail]) ->

%% @todo We need to kill the stream if it tries to send data before headers.

%% @todo Same as above.
case lists:keyfind(StreamID, #stream.id, Streams) of
#stream{version='HTTP/1.1'} ->
Expand Down Expand Up @@ -879,6 +893,9 @@ commands(State0=#state{ref=Ref, parent=Parent, socket=Socket, transport=Transpor
commands(State, StreamID, [stop|Tail]) ->
%% @todo Do we want to run the commands after a stop?
% commands(stream_terminate(State, StreamID, stop), StreamID, Tail).

%% @todo I think that's where we need to terminate streams.

maybe_terminate(State, StreamID, Tail, fin);
%% HTTP/1.1 does not support push; ignore.
commands(State, StreamID, [{push, _, _, _, _, _, _, _}|Tail]) ->
Expand Down
2 changes: 2 additions & 0 deletions src/cowboy_http2.erl
Expand Up @@ -418,7 +418,9 @@ commands(State=#state{socket=Socket, transport=Transport}, Stream=#stream{id=Str
[{data, IsFin, Data}|Tail]) ->
Transport:send(Socket, cow_http2:data(StreamID, IsFin, Data)),
commands(State, Stream#stream{local=IsFin}, Tail);

%% @todo data when local!=nofin

%% Send a file.
%%
%% @todo This implementation is terrible. A good implementation would
Expand Down
9 changes: 9 additions & 0 deletions src/cowboy_req.erl
Expand Up @@ -59,10 +59,12 @@
-export([set_resp_cookie/3]).
-export([set_resp_cookie/4]).
-export([set_resp_header/3]).
%% @todo set_resp_headers/2
-export([has_resp_header/2]).
%% @todo resp_header
-export([delete_resp_header/2]).
-export([set_resp_body/2]). %% @todo Use set_resp_body for iodata() | {sendfile ...}
%% @todo set_resp_body/3 with a ContentType or even Headers argument, to set content headers.
-export([has_resp_body/1]).
-export([reply/2]).
-export([reply/3]).
Expand Down Expand Up @@ -139,6 +141,7 @@ scheme(#{scheme := Scheme}) ->
host(#{host := Host}) ->
Host.

%% @todo The host_info is undefined if cowboy_router isn't used. Do we want to crash?
-spec host_info(req()) -> cowboy_router:tokens() | undefined.
host_info(#{host_info := HostInfo}) ->
HostInfo.
Expand All @@ -151,6 +154,7 @@ port(#{port := Port}) ->
path(#{path := Path}) ->
Path.

%% @todo The path_info is undefined if cowboy_router isn't used. Do we want to crash?
-spec path_info(req()) -> cowboy_router:tokens() | undefined.
path_info(#{path_info := PathInfo}) ->
PathInfo.
Expand All @@ -159,6 +163,7 @@ path_info(#{path_info := PathInfo}) ->
qs(#{qs := Qs}) ->
Qs.

%% @todo Might be useful to limit the number of keys.
-spec parse_qs(req()) -> [{binary(), binary() | true}].
parse_qs(#{qs := Qs}) ->
cow_qs:parse_qs(Qs).
Expand Down Expand Up @@ -333,6 +338,7 @@ parse_header(Name = <<"content-length">>, Req) ->
parse_header(Name, Req, 0, fun cow_http_hd:parse_content_length/1);
parse_header(Name = <<"cookie">>, Req) ->
parse_header(Name, Req, [], fun cow_cookie:parse_cookie/1);
%% @todo That header is abstracted out and should never reach cowboy_req.
parse_header(Name = <<"transfer-encoding">>, Req) ->
parse_header(Name, Req, [<<"identity">>], fun cow_http_hd:parse_transfer_encoding/1);
parse_header(Name, Req) ->
Expand Down Expand Up @@ -459,6 +465,8 @@ part(Buffer, Opts, Req=#{multipart := {Boundary, _}}) ->
{Data, Req2} = stream_multipart(Req, Opts),
part(<< Buffer2/binary, Data/binary >>, Opts, Req2);
{ok, Headers, Rest} ->
%% @todo We may want headers as a map. Need to check the
%% rules for multipart header parsing before taking a decision.
{ok, Headers, Req#{multipart => {Boundary, Rest}}};
%% Ignore epilogue.
{done, _} ->
Expand Down Expand Up @@ -529,6 +537,7 @@ set_resp_cookie(Name, Value, Req) ->
%%
%% The cookie value cannot contain any of the following characters:
%% ,; \t\r\n\013\014
%% @todo Fix the cookie_opts() type.
-spec set_resp_cookie(iodata(), iodata(), cookie_opts(), Req)
-> Req when Req::req().
set_resp_cookie(Name, Value, Opts, Req) ->
Expand Down
5 changes: 5 additions & 0 deletions src/cowboy_stream_h.erl
Expand Up @@ -152,6 +152,11 @@ report_crash(Ref, StreamID, Pid, Reason, Stacktrace) ->

%% Request process.

%% @todo This should wrap with try/catch to get the full error
%% in the stream handler. Only then can we decide what to do
%% about it. This means that we should remove any other try/catch
%% in the request process.

%% This hack is necessary because proc_lib does not propagate
%% stacktraces by default. This is ugly because we end up
%% having two try/catch instead of one (the one in proc_lib),
Expand Down
1 change: 1 addition & 0 deletions src/cowboy_websocket.erl
Expand Up @@ -102,6 +102,7 @@ websocket_upgrade(State, Req) ->
-> {ok, #state{}, Req} when Req::cowboy_req:req().
websocket_extensions(State, Req) ->
%% @todo We want different options for this. For example
%% @todo This should probably be configurable per handler, like timeout/hibernate.
%% * compress everything auto
%% * compress only text auto
%% * compress only binary auto
Expand Down
1 change: 1 addition & 0 deletions test/handlers/long_polling_h.erl
Expand Up @@ -14,6 +14,7 @@ init(Req, _) ->
{cowboy_loop, Req, 2, 5000, hibernate}.

info(timeout, Req, 0) ->
%% @todo Why 102?
{stop, cowboy_req:reply(102, Req), 0};
info(timeout, Req, Count) ->
erlang:send_after(200, self(), timeout),
Expand Down

0 comments on commit 3a05768

Please sign in to comment.