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

Fix HTTP server buffer #609

Merged
merged 4 commits into from
Apr 5, 2024
Merged

Fix HTTP server buffer #609

merged 4 commits into from
Apr 5, 2024

Conversation

vinc
Copy link
Owner

@vinc vinc commented Apr 2, 2024

Sometimes a call to socket.recv() doesn't return the whole receive buffer and some HTTP requests are not correctly parsed. This PR fixes this issue by rebuilding the whole buffer before parsing the request. It also fixes how the server join its root directory and the request path.

@vinc
Copy link
Owner Author

vinc commented Apr 2, 2024

This PR is used to test the e1000 driver in #337 on real hardware.

@vinc
Copy link
Owner Author

vinc commented Apr 3, 2024

Here's a test of various possibilities regarding the server directory and the request path:

~
> dhcp
ip:  10.0.2.15/24
gw:  10.0.2.2
dns: 10.0.2.3

~
> httpd
HTTP Server listening on 0.0.0.0:80
10.0.2.2 - - [2024-04-03 10:12:25 +0000] "GET /" 200 297
^C

~
> httpd -d /
HTTP Server listening on 0.0.0.0:80
10.0.2.2 - - [2024-04-03 10:12:34 +0000] "GET /" 200 309
10.0.2.2 - - [2024-04-03 10:12:38 +0000] "GET /tmp" 301 28
10.0.2.2 - - [2024-04-03 10:12:39 +0000] "GET /tmp/" 200 383
^C

~
> httpd -d /tmp
HTTP Server listening on 0.0.0.0:80
10.0.2.2 - - [2024-04-03 10:12:47 +0000] "GET /" 200 347
10.0.2.2 - - [2024-04-03 10:12:50 +0000] "GET /lisp" 301 28
10.0.2.2 - - [2024-04-03 10:12:51 +0000] "GET /lisp/" 200 377
^C

~
> httpd -d /tmp/
HTTP Server listening on 0.0.0.0:80
10.0.2.2 - - [2024-04-03 10:12:57 +0000] "GET /" 200 347
10.0.2.2 - - [2024-04-03 10:13:01 +0000] "GET /lisp" 301 28
10.0.2.2 - - [2024-04-03 10:13:02 +0000] "GET /lisp/" 200 377
^C

~
> /tmp

/tmp
> httpd
HTTP Server listening on 0.0.0.0:80
10.0.2.2 - - [2024-04-03 10:13:31 +0000] "GET /" 200 347
10.0.2.2 - - [2024-04-03 10:13:33 +0000] "GET /lisp" 301 28
10.0.2.2 - - [2024-04-03 10:13:34 +0000] "GET /lisp/" 200 377
^C

@vinc
Copy link
Owner Author

vinc commented Apr 3, 2024

This commit takes care of this case:

/
> httpd -d tmp
HTTP Server listening on 0.0.0.0:80
10.0.2.2 - - [2024-04-03 15:01:21 +0000] "GET /" 200 347
10.0.2.2 - - [2024-04-03 15:01:24 +0000] "GET /lisp" 301 28
10.0.2.2 - - [2024-04-03 15:01:26 +0000] "GET /lisp/" 200 377
^C

And it moves the trim on the root directory outside of the function to be done only once during startup to optimize it.

@vinc vinc marked this pull request as ready for review April 3, 2024 19:17
@vinc vinc merged commit d04d1a0 into trunk Apr 5, 2024
1 check passed
@vinc vinc deleted the feature/httpd branch April 5, 2024 07:40
@vinc vinc changed the title Fix HTTP server Fix HTTP server buffer Jun 3, 2024
@vinc vinc mentioned this pull request Jun 18, 2024
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.

1 participant