Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nhse d34 otp26 #1

Merged
merged 41 commits into from
Sep 9, 2024
Merged

Nhse d34 otp26 #1

merged 41 commits into from
Sep 9, 2024

Conversation

martinsumner
Copy link

Update from mochi/mochiweb for OTP 26 compliance

big-r81 and others added 30 commits August 11, 2022 10:07
from field-values to be RFC 7230 compliant.
Remove leading and trailing whitespaces
I'm still very new to Erlang but this seems pretty straightforward.
Bug in mochiweb_request:read_chunk_length/2 #188
Add a test for the chunked encoding fix
Added overview section. Added getting started section and a tutorial. Added benefits section. Added documentation section. Added contributing section.
Updated with the suggested changes
Fixed typo in line 5.
Fix rebar edoc and test in CI
This function can used during long running request callbacks to detect if the
client connection is closed.

If the request callback periodically streams data back to the client, the act
of writting to the client socket will detect if it is closed or not. However,
in cases when no data is sent back, and the client times-out and closes the
connection, it may be useful to be able to find out early and stop processing
the request on the server.

It turns out there is no easy way to detect if a passive mode socket is closed
in Erlang/OTP [1]. Neither one of inet:monitor/1, inet:info/1, inet:getstat/1
work. However, it is possible to do it by querying the TCP state info of the
socket. That option available in Linux since kernel 2.4 and on other Unix-like
OSes (NetBSD, OpenBSD, FreeBSD and MacOS). Windows also has a tcp info query
method however it is not reacheable via the gensockopts(2) standard socket API,
so it can't be queried from Erlang's inet:getopts/2 API.

[1] Using the newer socket module it's possible to detect if a socket is closed
by attempting a recv with a MSG_PEEK option. However, the regular gen_tcp OTP
module doesn't have a recv() variant which takes extra options. In addition,
the new socket implementation still feels rather experimental. (It's not the
default even in the latest OTP 26 release).
Matching of floating-point zeroes will change in OTP-27 so that -0.0 will
no longer match a non-negative 0.0. OTP-26.1 warns about such constructs,
which in mochiweb results in:

src/mochinum.erl:47:8: Warning: matching on the float 0.0 will no longer also match -0.0 in OTP 27. If you specifically intend to match 0.0 alone, write +0.0 instead.

Fixed by switching from a match to a numerical comparison.
mochinum:digits/1: fix handling of -0.0 for OTP-26.1/27.0
 * Use latest patch levels for 24 and 25.
 * Add 26 to the list.

In Erlang 26 TLS `verify` option switched the default value from `verify_none`
to `verify_peer` [1]. So had to explictly set it in the test client.

[1] https://www.erlang.org/blog/otp-26-highlights/#ssl-safer-defaults
@@ -215,6 +215,9 @@ tokenize_header_value(undefined) ->
tokenize_header_value(V) ->
reversed_tokens(trim_and_reverse(V, false), [], []).

trim_leading_and_trailing_ws(S) ->

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since otp20 there is string:trim(S, both) that would help you a long way...
But possibly some other guarantees are given here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there may be a difference in the handling of "\r", which isn't referred to in this function. For now, I'm preferring to de-risk the change and not make any assumptions.

@martinsumner martinsumner merged commit e83530d into nhse-develop-3.4 Sep 9, 2024
2 checks passed
@martinsumner martinsumner deleted the nhse-d34-otp26 branch September 9, 2024 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants