HTTP

From Training Material
Jump to navigation Jump to search
title
HTTP
author
Sam Bashton (NobleProg Ltd)

HTTP ⌘

  • Stateless, no support for sessions
  • A single TCP connection is created per request
  • For HTTP 1.0, multiple requests can be 'pipelined' in 1.1

HTTP Requests ⌘

A very simple HTTP request ⌘

`GET / HTTP/1.0`

HTTP Virtual Hosting ⌘

  • Imagine we wish to host www.example.com and www.example.es on the same server
  • HTTP 1.0 requires that every website has a unique IP
  • This is massively wasteful of IPs, as well as requiring extra administration
  • Solution: HTTP/1.1 and virtual hosts

A simple HTTP 1.1 request ⌘

  • GET / HTTP/1.1
  • Host: www.example.com

Cookies ⌘

  • HTTP is stateless
  • How does the web application know who the user is?
  • Cookies

A simple HTTP request with cookies ⌘

  • GET / HTTP/1.1
  • Host: www.example.es
  • Cookie: Session=ABC12345

HTTP Responses ⌘

HTTP Response codes ⌘

  • Many different HTTP response codes
  • Most common:
  • 200 OK
  • 301 Permanent Redirect
  • 302 Temporary Redirect
  • 404 Not found
  • 500 Internal server error
  • 503 Bad gateway

Example request/response ⌘

  • GET / HTTP1.0
  • HTTP/1.0 200 OK
  • Content-Type: text/html
  • Cache-Control: private
  • Content-Type: text/html; charset=UTF-8
  • Set-Cookie: SESSION=ABCDEF12345

Try it out ⌘

  • telnet www.google.com 80
  • GET / HTTP/1.0
  • telnet www.google.com 80
  • GET / HTTP/1.1
  • Host: www.google.es