Implementing HTTP
How should we go about implementing HTTP on top of our TCP codebase? Although there are a few moving parts, the fundamental requirement is that we need to implement a handleConnection() function that does four things:
-
Generate an HTTP request matching the format described in the previous section.
-
Transmit the request.
-
Receive an HTTP response.
-
Decode the HTTP response into a useful form.
Transmitting and receiving the request can be performed with read() and write(), which we looked at in the first chapter. The tricky part is in representing HTTP requests and responses as Scala objects, and in encoding and decoding those to the wire protocol we described in the previous section. If we model the request and response as regular ...
Get Modern Systems Programming with Scala Native now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.