

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Parsing the Body
incomplete
2: Live Body
incomplete
3: Body Review
incomplete
This lesson's interactive features are locked, please to keep using them
Take a look at the struct we've been parsing requests into:
type Request struct {
RequestLine RequestLine
Headers headers.Headers
Body []byte
// ...
}
Now compare it to the official Golang http.Request struct:
type Request struct {
Proto string
Method string
URL *url.URL
Header http.Header
Body io.ReadCloser
// ...
}
There are a few differences:
RequestLine struct, while they've elevated the Method, Target, and Version into their own top-level fields. It's basically the same data, but the layout is a bit different.Headers struct, they named theirs Header. Again, same data, slightly different layout and naming. I prefer to call them "headers" because that's usually how web developers refer to them, the Go stdlib refers to the entire collection of field lines as a "header"... but I digress.Body field that just stores the entire body as a []byte in memory, while the Go stdlib has an io.ReadCloser interface. Our solution is perhaps simpler, but it's more limiting to the users of our library... we force them to load the entire body into memory, before interacting with it. The Go stdlib allows the user to read the body in chunks, or even stream it to a file, which is often necessary for large bodies. More on this later.