Skip to content
This repository has been archived by the owner on Jan 21, 2025. It is now read-only.

Reset connection when appropriate + some code cleanup #180

Merged
merged 2 commits into from
Dec 19, 2024
Merged

Conversation

mathieucarbou
Copy link
Owner

I went over the code base to do a little cleanup of the calls to close() which should instead be abort when related to connection problems or request parsing problems.

ChatGPT summarises the use cases pretty well: https://chatgpt.com/share/6763e68c-8900-8007-b540-16156d04d13c

@mathieucarbou mathieucarbou self-assigned this Dec 19, 2024
Comment on lines -795 to -800
if (_response == NULL) {
_client->close(true);
_onDisconnect();
_sent = true;
return;
}
Copy link
Owner Author

Choose a reason for hiding this comment

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

I've removed this weird use case where a user could just decide to close the connection by doing send(null). IMO this is wrong because once a correctly formed http request goes through, it should be handled as a http request and a response should be sent.

closing the connection eagerly would also break the middleware chain since middleware acting after the handler is executing won't have any effect.

Copy link
Owner Author

Choose a reason for hiding this comment

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

send(null) now has the same effect has an empty handler:

  // curl -v -X GET http://192.168.4.1/handler-not-sending-response
  server.on("/handler-not-sending-response", HTTP_GET, [](AsyncWebServerRequest* request) {
    // handler forgot to send a response to the client => 501 Not Implemented
  });

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks good to me!

@mathieucarbou mathieucarbou merged commit cd882c4 into main Dec 19, 2024
44 checks passed
@mathieucarbou mathieucarbou deleted the refac branch December 19, 2024 09:53
@vortigont
Copy link
Collaborator

ChatGPT summarises the use cases pretty well: https://chatgpt.com/share/6763e68c-8900-8007-b540-16156d04d13c

Wow! Looks like this thing could be hired instead of ppl like me :)))
Never tried it so far actually, should give a try some time

@mathieucarbou
Copy link
Owner Author

ChatGPT summarises the use cases pretty well: https://chatgpt.com/share/6763e68c-8900-8007-b540-16156d04d13c

Wow! Looks like this thing could be hired instead of ppl like me :))) Never tried it so far actually, should give a try some time

I also rarely use it, but only when I want to get a summary of something instead of searching on Internet. Which it id a great job here I think ;-)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants