Allow to attach reasons to close frames#142
Open
mebsout wants to merge 1 commit into
Open
Conversation
copy
reviewed
Jul 4, 2025
|
|
||
| let close code = | ||
| let content = Bytes.create 2 in | ||
| let close ?reason code = |
Collaborator
There was a problem hiding this comment.
This should check the maximum length (123 bytes, according to wikipedia)
Comment on lines
+96
to
+101
| let close ?reason code = | ||
| let content = match reason with | ||
| | None -> Bytes.create 2 | ||
| | Some reason -> Bytes.init (String.length reason + 2) @@ fun i -> | ||
| if i <= 1 then '\000' else reason.[i - 2] | ||
| in |
Collaborator
There was a problem hiding this comment.
Suggested change
| let close ?reason code = | |
| let content = match reason with | |
| | None -> Bytes.create 2 | |
| | Some reason -> Bytes.init (String.length reason + 2) @@ fun i -> | |
| if i <= 1 then '\000' else reason.[i - 2] | |
| in | |
| let close ?(reason=String.empty) code = | |
| let content = Bytes.create (2 + String.length reason) in | |
| Bytes.blit_string reason 0 content 2 (String.length reason); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This MR allows applications to attach a reason when sending a close frame, as per https://datatracker.ietf.org/doc/html/rfc6455#section-5.5.1.
Note that we could add reasons for the various cases in which the library closes the connection.