mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
Cleanup various comments
This commit is contained in:
parent
ea80e7a309
commit
d47e22edaa
2 changed files with 6 additions and 40 deletions
|
@ -52,18 +52,10 @@
|
||||||
name = undefined :: binary() | undefined
|
name = undefined :: binary() | undefined
|
||||||
}).
|
}).
|
||||||
|
|
||||||
%% @todo We need a state where we wait for the stream process to ask for the body.
|
%% @todo We need a state where we wait for the stream process to ask for the body
|
||||||
%% OR DO WE
|
%% and do not attempt to read from the socket while in that state (we should read
|
||||||
|
%% up to a certain length, and then wait, basically implementing flow control but
|
||||||
%% In HTTP/2 we start receiving data before the body asks for it, even if optionally
|
%% by not reading from the socket when the window is empty).
|
||||||
%% (and by default), so we need to be able to do the same for HTTP/1.1 too. This means
|
|
||||||
%% that when we receive data (up to a certain limit, we read from the socket and decode.
|
|
||||||
%% When we reach a limit, we stop reading from the socket momentarily until the stream
|
|
||||||
%% process asks for more or the stream ends.
|
|
||||||
|
|
||||||
%% This means that we need to keep a buffer in the stream handler (until the stream
|
|
||||||
%% process asks for it). And that we need the body state to indicate how much we have
|
|
||||||
%% left to read (and stop/start reading from the socket depending on value).
|
|
||||||
|
|
||||||
-record(ps_body, {
|
-record(ps_body, {
|
||||||
%% @todo flow
|
%% @todo flow
|
||||||
|
@ -135,9 +127,6 @@ init(Parent, Ref, Socket, Transport, Opts) ->
|
||||||
terminate(undefined, {socket_error, Reason, 'An error has occurred on the socket.'})
|
terminate(undefined, {socket_error, Reason, 'An error has occurred on the socket.'})
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% @todo Send a response depending on in_state and whether one was already sent.
|
|
||||||
%% @todo If we skip the body, skip for a specific duration.
|
|
||||||
|
|
||||||
before_loop(State=#state{socket=Socket, transport=Transport}, Buffer) ->
|
before_loop(State=#state{socket=Socket, transport=Transport}, Buffer) ->
|
||||||
%% @todo disable this when we get to the body, until the stream asks for it?
|
%% @todo disable this when we get to the body, until the stream asks for it?
|
||||||
%% Perhaps have a threshold for how much we're willing to read before waiting.
|
%% Perhaps have a threshold for how much we're willing to read before waiting.
|
||||||
|
@ -608,7 +597,6 @@ request(Buffer, State0=#state{ref=Ref, transport=Transport, peer=Peer, in_stream
|
||||||
scheme => Scheme,
|
scheme => Scheme,
|
||||||
host => Host,
|
host => Host,
|
||||||
port => Port,
|
port => Port,
|
||||||
%% @todo The path component needs to be normalized.
|
|
||||||
path => Path,
|
path => Path,
|
||||||
qs => Qs,
|
qs => Qs,
|
||||||
version => Version,
|
version => Version,
|
||||||
|
@ -623,7 +611,6 @@ request(Buffer, State0=#state{ref=Ref, transport=Transport, peer=Peer, in_stream
|
||||||
State = case HasBody of
|
State = case HasBody of
|
||||||
true ->
|
true ->
|
||||||
State0#state{in_state=#ps_body{
|
State0#state{in_state=#ps_body{
|
||||||
%% @todo Don't need length anymore?
|
|
||||||
transfer_decode_fun = TDecodeFun,
|
transfer_decode_fun = TDecodeFun,
|
||||||
transfer_decode_state = TDecodeState
|
transfer_decode_state = TDecodeState
|
||||||
}};
|
}};
|
||||||
|
@ -659,8 +646,6 @@ is_http2_upgrade(#{<<"connection">> := Conn, <<"upgrade">> := Upgrade,
|
||||||
is_http2_upgrade(_, _) ->
|
is_http2_upgrade(_, _) ->
|
||||||
false.
|
false.
|
||||||
|
|
||||||
%% Upgrade through an HTTP/1.1 request.
|
|
||||||
|
|
||||||
%% Prior knowledge upgrade, without an HTTP/1.1 request.
|
%% Prior knowledge upgrade, without an HTTP/1.1 request.
|
||||||
http2_upgrade(State=#state{parent=Parent, ref=Ref, socket=Socket, transport=Transport,
|
http2_upgrade(State=#state{parent=Parent, ref=Ref, socket=Socket, transport=Transport,
|
||||||
opts=Opts, peer=Peer}, Buffer) ->
|
opts=Opts, peer=Peer}, Buffer) ->
|
||||||
|
@ -673,6 +658,7 @@ http2_upgrade(State=#state{parent=Parent, ref=Ref, socket=Socket, transport=Tran
|
||||||
'Clients that support HTTP/2 over TLS MUST use ALPN. (RFC7540 3.4)'})
|
'Clients that support HTTP/2 over TLS MUST use ALPN. (RFC7540 3.4)'})
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
%% Upgrade via an HTTP/1.1 request.
|
||||||
http2_upgrade(State=#state{parent=Parent, ref=Ref, socket=Socket, transport=Transport,
|
http2_upgrade(State=#state{parent=Parent, ref=Ref, socket=Socket, transport=Transport,
|
||||||
opts=Opts, peer=Peer}, Buffer, HTTP2Settings, Req) ->
|
opts=Opts, peer=Peer}, Buffer, HTTP2Settings, Req) ->
|
||||||
%% @todo
|
%% @todo
|
||||||
|
|
|
@ -481,7 +481,7 @@ commands(State=#state{socket=Socket, transport=Transport, encode_state=EncodeSta
|
||||||
commands(State1#state{encode_state=EncodeState}, Stream1, Tail)
|
commands(State1#state{encode_state=EncodeState}, Stream1, Tail)
|
||||||
end;
|
end;
|
||||||
%% @todo response when local!=idle
|
%% @todo response when local!=idle
|
||||||
%% Send response headers and initiate chunked encoding.
|
%% Send response headers.
|
||||||
commands(State=#state{socket=Socket, transport=Transport, encode_state=EncodeState0},
|
commands(State=#state{socket=Socket, transport=Transport, encode_state=EncodeState0},
|
||||||
Stream=#stream{id=StreamID, local=idle}, [{headers, StatusCode, Headers0}|Tail]) ->
|
Stream=#stream{id=StreamID, local=idle}, [{headers, StatusCode, Headers0}|Tail]) ->
|
||||||
Headers = Headers0#{<<":status">> => status(StatusCode)},
|
Headers = Headers0#{<<":status">> => status(StatusCode)},
|
||||||
|
@ -490,16 +490,6 @@ commands(State=#state{socket=Socket, transport=Transport, encode_state=EncodeSta
|
||||||
commands(State#state{encode_state=EncodeState}, Stream#stream{local=nofin}, Tail);
|
commands(State#state{encode_state=EncodeState}, Stream#stream{local=nofin}, Tail);
|
||||||
%% @todo headers when local!=idle
|
%% @todo headers when local!=idle
|
||||||
%% Send a response body chunk.
|
%% Send a response body chunk.
|
||||||
%%
|
|
||||||
%% @todo WINDOW_UPDATE stuff require us to buffer some data.
|
|
||||||
%%
|
|
||||||
%% When the body is sent using sendfile, the current solution is not
|
|
||||||
%% very good. The body could be too large, blocking the connection.
|
|
||||||
%% Also sendfile technically only works over TCP, so it's not that
|
|
||||||
%% useful for HTTP/2. At the very least the sendfile call should be
|
|
||||||
%% split into multiple calls and flow control should be used to make
|
|
||||||
%% sure we only send as fast as the client can receive and don't block
|
|
||||||
%% anything.
|
|
||||||
commands(State0, Stream0=#stream{local=nofin}, [{data, IsFin, Data}|Tail]) ->
|
commands(State0, Stream0=#stream{local=nofin}, [{data, IsFin, Data}|Tail]) ->
|
||||||
{State, Stream} = send_data(State0, Stream0, IsFin, Data),
|
{State, Stream} = send_data(State0, Stream0, IsFin, Data),
|
||||||
commands(State, Stream, Tail);
|
commands(State, Stream, Tail);
|
||||||
|
@ -507,16 +497,6 @@ commands(State0, Stream0=#stream{local=nofin}, [{data, IsFin, Data}|Tail]) ->
|
||||||
%% @todo data when local!=nofin
|
%% @todo data when local!=nofin
|
||||||
|
|
||||||
%% Send a file.
|
%% Send a file.
|
||||||
%%
|
|
||||||
%% @todo This implementation is terrible. A good implementation would
|
|
||||||
%% need to check that Bytes is exact (or we need to document that we
|
|
||||||
%% trust it to be exact), and would need to send the file asynchronously
|
|
||||||
%% in many data frames. Perhaps a sendfile call should result in a
|
|
||||||
%% process being created specifically for this purpose. Or perhaps
|
|
||||||
%% the protocol should be "dumb" and the stream handler be the one
|
|
||||||
%% to ensure the file is sent in chunks (which would require a better
|
|
||||||
%% flow control at the stream handler level). One thing for sure, the
|
|
||||||
%% implementation necessarily varies between HTTP/1.1 and HTTP/2.
|
|
||||||
commands(State0, Stream0=#stream{local=nofin},
|
commands(State0, Stream0=#stream{local=nofin},
|
||||||
[{sendfile, IsFin, Offset, Bytes, Path}|Tail]) ->
|
[{sendfile, IsFin, Offset, Bytes, Path}|Tail]) ->
|
||||||
{State, Stream} = send_data(State0, Stream0, IsFin, {sendfile, Offset, Bytes, Path}),
|
{State, Stream} = send_data(State0, Stream0, IsFin, {sendfile, Offset, Bytes, Path}),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue