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

Specify connection: keep-alive in exercise 1-6 #1378

Merged
merged 2 commits into from
Dec 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions book/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -984,12 +984,14 @@ print the entire HTML file as if it was text. You'll want to have also
implemented Exercise 1-4.

1-6 *Keep-alive*. Implement Exercise 1-1; however, do not send
the `Connection: close` header. Instead, when reading the body from
the socket, only read as many bytes as given in the `Content-Length`
header and don't close the socket afterward. Instead, save the
socket, and if another request is made to the same server reuse the
same socket instead of creating a new one. This will speed up repeated
requests to the same server, which are common.
the `Connection: close` header (send `Connection: keep-alive` instead).
When reading the body from the socket, only read as many bytes as given
in the `Content-Length` header and don't close the socket afterward.
Instead, save the socket, and if another request is made to the same server
reuse the same socket instead of creating a new one.
(You'll also need to pass the `"rb"` option to `makefile` or the value reported
chrishtr marked this conversation as resolved.
Show resolved Hide resolved
by `Content-Length` might not match the length of the string you're reading.)
This will speed up repeated requests to the same server, which are common.

1-7 *Redirects*. Error codes in the 300 range request a redirect. When
your browser encounters one, it should make a new request to the URL
Expand Down
Loading