browserengineering / book

Web browser engineering (a book)

Home Page:https://browser.engineering/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Consider adding an exercise on reusing sockets

DanielRosenwasser opened this issue · comments

On Downloading Web Pages, there is a "Go further" section on supporting redirects. One of the things that becomes "obvious" if you know about the handshake process is that closing and opening a socket is kind of wasteful.

Once you support HTTP 1.1, it seems like you should be able to reuse the socket by not immediately closing it, and then requesting the Location of a redirect. Would that be a useful exercise for readers, or is that just an "obvious" thing that you already expect readers to do?

+1, you can use the keep-alive option for Connection and then re-use the socket - I think this would be useful to mention 🙂

Do you need the keep-alive header? I managed to get by without it and the MDN docs seem to imply it's the default on HTTP 1.1.

You don't need keep-alive in HTTP/1.1, it's the default (this is in fact why this book uses 1.0). Implementing "keep-alive" is a good exercise, and I think I drafted one at some point. I didn't think of using it for redirects though, that's a good idea. Perhaps I'll have something like this in a later chapter, once we're requesting CSS or JS.

One specific issue I hit when I tried to reuse sockets was that that in the second chapter, the link

http://www.zggdwx.com/xiyou/1.html

redirects to

https://www.zggdwx.com/xiyou/1.html

My understanding is that you can't reuse the socket at all, and that would be a potential gotcha. That's not to say that it's not still a worthwhile addition.

Ooh, I'll look into this. In reality we need to self-host all of our examples and exercises, because things like this change!