Skip to content

Commit cfc6236

Browse files
committed
refactor: clean up ELP lint warnings across all modules
Use map syntax instead of maps:put/3, wrap macro bodies in parens to prevent precedence issues, drop the stale -dialyzer nowarn on handle_headers_complete (dialyzer is fine without it now), swap maps:find for map pattern matching in flush_stream_send_buffer, replace maps:to_list comprehension with maps:fold in flush_all_send_buffers, and strip unused stream_state record fields (data_buffer, priority, dependency, weight).
1 parent 079c7b2 commit cfc6236

4 files changed

Lines changed: 20 additions & 22 deletions

File tree

src/gen_http.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ negotiate_protocol(https, Address, Port, Opts, Protocols) ->
534534
%% Add ALPN to transport options
535535
TransportOpts = maps:get(transport_opts, Opts, []),
536536
NewTransportOpts = [{alpn_advertise, AlpnProtocols} | TransportOpts],
537-
NewOpts = maps:put(transport_opts, NewTransportOpts, Opts),
537+
NewOpts = Opts#{transport_opts => NewTransportOpts},
538538

539539
%% Try HTTP/2 first if in protocol list
540540
case lists:member(http2, Protocols) of

src/gen_http_h1.erl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ get_socket(#gen_http_h1_conn{socket = Socket}) ->
333333
%% Attach metadata to connections (e.g., pool ID, metrics, tags).
334334
-spec put_private(conn(), Key :: term(), Value :: term()) -> conn().
335335
put_private(#gen_http_h1_conn{private = Private} = Conn, Key, Value) ->
336-
Conn#gen_http_h1_conn{private = maps:put(Key, Value, Private)}.
336+
Conn#gen_http_h1_conn{private = Private#{Key => Value}}.
337337

338338
%% @doc Get a private value from the connection.
339339
%%
@@ -699,7 +699,6 @@ parse_headers(Buffer, ReqState, HeadersAcc) ->
699699
{error, protocol_error(invalid_header)}
700700
end.
701701

702-
-dialyzer({nowarn_function, handle_headers_complete/3}).
703702
handle_headers_complete(Rest, ReqState, Headers) ->
704703
HeadersResp = {headers, ReqState#request_state.ref, Headers},
705704
BodyState = determine_body_state(ReqState#request_state.status, Headers),

src/gen_http_h2.erl

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,12 @@
138138
recv_window :: non_neg_integer(),
139139

140140
%% Data
141-
data_buffer = <<>> :: binary(),
142141
%% For CONTINUATION frames
143142
headers_buffer = <<>> :: binary(),
144143
%% Outbound data waiting for flow control window
145144
send_buffer = <<>> :: binary(),
146145
%% Whether END_STREAM should be sent after send_buffer drains
147-
send_end_stream = false :: boolean(),
148-
149-
%% Priority (optional)
150-
priority :: non_neg_integer() | undefined,
151-
dependency :: stream_id() | undefined,
152-
weight :: pos_integer() | undefined
146+
send_end_stream = false :: boolean()
153147
}).
154148

155149
-type conn() :: #gen_http_h2_conn{}.
@@ -424,7 +418,7 @@ get_window_size(Conn, StreamId) ->
424418
%% Attach metadata to connections (e.g., pool ID, metrics, tags).
425419
-spec put_private(conn(), Key :: term(), Value :: term()) -> conn().
426420
put_private(#gen_http_h2_conn{private = Private} = Conn, Key, Value) ->
427-
Conn#gen_http_h2_conn{private = maps:put(Key, Value, Private)}.
421+
Conn#gen_http_h2_conn{private = Private#{Key => Value}}.
428422

429423
%% @doc Get a private value from the connection.
430424
%%
@@ -873,7 +867,7 @@ handle_settings_frame(Conn, Flags, Params) ->
873867
%% Server sent SETTINGS, update and send ACK
874868
NewRemoteSettings = lists:foldl(
875869
fun({Key, Value}, Acc) ->
876-
maps:put(Key, Value, Acc)
870+
Acc#{Key => Value}
877871
end,
878872
Conn#gen_http_h2_conn.remote_settings,
879873
Params
@@ -1109,8 +1103,8 @@ handle_window_update_frame(Conn, StreamId, Increment) ->
11091103
-spec flush_stream_send_buffer(conn(), stream_id()) ->
11101104
{ok, conn(), [h2_response()]}.
11111105
flush_stream_send_buffer(Conn, StreamId) ->
1112-
case maps:find(StreamId, Conn#gen_http_h2_conn.streams) of
1113-
{ok, Stream} ->
1106+
case Conn#gen_http_h2_conn.streams of
1107+
#{StreamId := Stream} ->
11141108
case Stream#stream_state.send_buffer of
11151109
<<>> ->
11161110
{ok, Conn, []};
@@ -1121,19 +1115,24 @@ flush_stream_send_buffer(Conn, StreamId) ->
11211115
),
11221116
{ok, Conn2, []}
11231117
end;
1124-
error ->
1118+
_ ->
11251119
{ok, Conn, []}
11261120
end.
11271121

11281122
%% @doc Flush send buffers for all streams that have pending data.
11291123
-spec flush_all_send_buffers(conn()) ->
11301124
{ok, conn(), [h2_response()]}.
11311125
flush_all_send_buffers(Conn) ->
1132-
StreamIds = [
1133-
Id
1134-
|| {Id, S} <- maps:to_list(Conn#gen_http_h2_conn.streams),
1135-
byte_size(S#stream_state.send_buffer) > 0
1136-
],
1126+
StreamIds = maps:fold(
1127+
fun(Id, S, Acc) ->
1128+
case byte_size(S#stream_state.send_buffer) > 0 of
1129+
true -> [Id | Acc];
1130+
false -> Acc
1131+
end
1132+
end,
1133+
[],
1134+
Conn#gen_http_h2_conn.streams
1135+
),
11371136
flush_streams(Conn, StreamIds).
11381137

11391138
-spec flush_streams(conn(), [stream_id()]) -> {ok, conn(), [h2_response()]}.

src/gen_http_parser_h1.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
-type header_name() :: binary().
2626
-type header_value() :: binary().
2727

28-
-define(IS_DIGIT(Val), Val >= $0 andalso Val =< $9).
29-
-define(IS_ALPHA(Val), Val >= $A andalso Val =< $Z orelse Val >= $a andalso Val =< $z).
28+
-define(IS_DIGIT(Val), (Val >= $0 andalso Val =< $9)).
29+
-define(IS_ALPHA(Val), ((Val >= $A andalso Val =< $Z) orelse (Val >= $a andalso Val =< $z))).
3030
-define(IS_HEX(Val),
3131
(?IS_DIGIT(Val) orelse (Val >= $A andalso Val =< $F) orelse (Val >= $a andalso Val =< $f))
3232
).

0 commit comments

Comments
 (0)