Slide 1

Slide 1 text

~/ on the Range

Slide 2

Slide 2 text

HTTP/1.1 “Physics for Physics Majors”

Slide 3

Slide 3 text

Client Server Proxy Gateway Tunnel Request Response

Slide 4

Slide 4 text

// HTTP server. var http = require("http") http.Server(function (request, response) { response.writeHead(200, { "Content-Type": "text/plain", "Content-Length": 13 }) response.end("Hello, world.") }).listen(1900)

Slide 5

Slide 5 text

// TCP client (`telnet`). var net = require("net") net.connect(1900, function () { this.write("GET / HTTP/1.1\r\n") this.end("\r\n") }).pipe(process.stdout)

Slide 6

Slide 6 text

HTTP/1.1 200 OK Content-Type: text/plain Content-Length: 13 Date: Tue, 16 Oct 2012 00:20:00 GMT Connection: keep-alive Hello, world. Status Line Headers Body

Slide 7

Slide 7 text

100 200 300 400 500 Information Request acknowledged Success Received, understood, and accepted Redirection Client intervention Client Error Bad request Server Error Unfulfillable request

Slide 8

Slide 8 text

General Request Response Entity Cache-Control, Connection, Date, Pragma, Trailer, Transfer-Encoding, Upgrade, Via, Warning Accept, Accept-Charset, Accept-Encoding, Accept-Language, Authorization, Expect, From, Host, If-Match, If-Modified- Since, If-None-Match, If-Range, If-Unmodified-Since, Max- Forwards, Proxy-Authorization, Range, Referer, TE, User-Agent Accept-Ranges, Age, ETag, Location, Proxy- Authenticate, Retry-After, Server, Vary, WWW- Authenticate Allow, Content-Encoding, Content-Language, Content- Length, Content-Location, Content-MD5, Content-Range, Content-Type, Expires, Last-Modified

Slide 9

Slide 9 text

Encoding

Slide 10

Slide 10 text

HTTP/1.1 200 OK Content-Type: text/plain Date: Tue, 16 Oct 2012 00:20:00 GMT Connection: keep-alive Transfer-Encoding: chunked d Hello, world. 0 Hex Size Indicators parseInt("d", 16) == 13

Slide 11

Slide 11 text

Content-Type Content-Encoding The media type of the entity gzip compression; requires decoding

Slide 12

Slide 12 text

Methods

Slide 13

Slide 13 text

GET HEAD POST PUT DELETE OPTIONS TRACE CONNECT

Slide 14

Slide 14 text

Ranges

Slide 15

Slide 15 text

Request Response Range, If-Range Accept-Ranges: bytes Range, If-Range Content-Range Range, If-Range Content-Length Content-Range Content-Length Content-Range Date Content-Range ETag, Content-Location, Expires, Cache-Control, Vary

Slide 16

Slide 16 text

First 500 bytes Next 500 bytes Last 500 bytes Last 500 bytes First and last bytes only bytes=0-499 bytes=500-999 bytes=-500 bytes=9500- bytes=0-0,-1 npm install range-parser

Slide 17

Slide 17 text

First 500 bytes Next 500 bytes All except for first 500 bytes Last 500 bytes Requested range not satisfiable bytes 0-499/1234 bytes 500-999/1234 bytes 500-1233/1234 bytes 734-1233/1234 *

Slide 18

Slide 18 text

Non-Contiguous Ranges

Slide 19

Slide 19 text

HTTP/1.1 206 Partial Content Date: Tue, 16 Oct 2012 00:20:00 GMT Accept-Ranges: bytes Content-Type: multipart/byteranges; boundary=BOUNDARY --BOUNDARY ... --BOUNDARY ... --BOUNDARY--

Slide 20

Slide 20 text

Content-Type: text/plain Content-Range: bytes 1602-1745/422279 The Hypertext Transfer Protocol (HTTP) is an application-level protocol for distributed, collaborative, hypermedia information systems. Content-Type: text/plain Content-Range: bytes 193409-193586/422279 be displayed when this actually happens. The indication need not be a dialog box; it could be an icon (for example, a picture of a rotting fish) or some other indicator.

Slide 21

Slide 21 text

Partial PUT Requests

Slide 22

Slide 22 text

var contentRange, pattern, match if (request.method == "PUT") { contentRange = request.headers["content-range"] pattern = /^bytes ((?:\d+-\d+)|\*)\/(\d+|\*)$/ if ((match = pattern.exec(contentRange))) { request.pipe(fs.createWriteStream("target", { "start": +match[1].split("-")[0] || 0, "flags": "r+" })) } }

Slide 23

Slide 23 text

Use Cases

Slide 24

Slide 24 text

Resuming interrupted downloads Efficiently retrieving large media files Download accelerators Granular caching

Slide 25

Slide 25 text

Thank you! @kitcambridge git.io/kit