Lesson 9.4

Finishing res.send

res.send infers a content-type from its argument, the charset that prevents mojibake, the chapter's bodyless-response policy, and the MIME table behind res.type.

30 minsrc/mime.js, src/status.js, src/response.js
  • Infer text/html, application/json, or application/octet-stream from res.send's argument, in the correct type-check order.
  • Suppress content for 204/205/304 while giving each status valid HTTP/1.1 length framing.
  • Map an extension or shorthand to a MIME type, appending charset to text types only.
Locked

This chapter is part of the framework capstone. Chapters 1 and 2 are free to build - unlock the rest to keep going.

Unlock the depth