HTTP 2.0 and NodeJS

and SPDY

Halvard Skogsrud, hskogsru@thoughtworks.com

Agenda

  • Why HTTP 2.0?
  • TCP refresher
  • SPDY and HTTP 2.0
  • New features
  • Protocol negotation
  • Server push demo

Why HTTP 2.0?

Latency is the killer

HTTP 1.1 State of the Art

  • Use persistent TCP connections
  • Pipelining troublesome, so not used
  • Multiple connections for parallelism
  • Resource sharding for more parallelism
  • Inlining and image spriting for fewer round trips

TLS Handshake

INITCWND

TCP Congestion Control

TCP Slow Start

What is SPDY?

  • An experimental protocol from Google, created in 2009
  • The starting point for IETF's HTTP 2.0 standardisation work
  • Not an acronym
  • Keeps all existing HTTP status codes and headers
  • Binary!

HTTP 2.0 is almost here

HTTP 2.0 Specification

Who supports SPDY?

Browsers:
Chrome (desktop, iOS, Android), Firefox, Opera, IE 11+ (on Win8+), Amazon Silk

Websites:
Google, Facebook, Twitter, and more.

Application servers/platforms:
Apache (mod_spdy), Nginx, Ruby, Python, NodeJS, Java (Jetty and Netty)

Networking tools:
F5, Wireshark, cURL (in progress)

Who supports HTTP 2.0?

HTTP 2.0 Implementations

SPDY and HTTP 2.0 Goals

  • Reduce end-user perceived latency
  • Minimise deployment complexity: Don't require changes to existing network infrastructure
  • Avoid the need for web site and web application creators to make changes
  • Improve web security

SPDY and HTTP 2.0 Features

  • Multiplex requests over a single TCP connection: Overcome TCP slow start
  • Header compression: Reduce bandwidth usage
  • Request prioritisation: Important resources arrive first
  • Server push: Reduce number of round trips
  • Run everything over TLS*
  • No changes to methods, status codes, headers, or standard ports (80, 443)

Multiplexing

Header compression

Here be dragons!

  • Why? Lots of mostly repeated header content in every request and response
  • Initial spec used zlib but then CRIME came along
  • CRIME (Compression Ratio Info-leak Made Easy): compression and encryption don't mix well
  • Inject different plaintext and observe change in compressed size
  • Now using HPACK, this has slowed implementation effort

Server push

Shove resources down browsers' throats

  • Send resources to browsers unsolicited
  • By the time the browser has parsed the HTML/JS and wants to request the resource, it's already in the browser cache
if (request.url === '/index.html' && response.push) {
  var stream = response.push('/jquery.js', {'Content-Type': 'text/javascript'}, 
  fs.createReadStream('/jquery.js').pipe(stream);
}

Negotiating HTTP 1.1 vs 2.0 vs SPDY

  • NPN: Next Protocol Negotiation (SPDY)
  • ALPN: Application Layer Protocol Negotiation (HTTP 2.0)
  • These are TLS extensions
  • Upgrade handshake for HTTP 2.0 over non-TLS connection
  • Allows SPDY/HTTP 2.0 to run on the same ports as HTTP(S)

SPDY vs HTTP 2.0

  • Protocol identification headers
  • NPN vs ALPN for negotiating HTTP 1.1 vs 2.0 vs SPDY
  • HTTP 2.0 supports plaintext mode via 'Upgrade' handshake*

NodeJS Support

  • SPDY support available for Connect-based applications via node-spdy
  • Automated server push Express middleware via spdy-referrer-push
  • HTTP 2.0 support available via node-http2
  • BUT ALPN support will not be available until OpenSSL has stabilised its implementation. Or use a forked version of NodeJS.

Server push demo!

References

Thanks!

npm https://github.com/halvards/spdy-referrer-push