15-213 The course that gives CMU its Zip! Web Services Web - - PowerPoint PPT Presentation

15 213
SMART_READER_LITE
LIVE PREVIEW

15-213 The course that gives CMU its Zip! Web Services Web - - PowerPoint PPT Presentation

15-213 The course that gives CMU its Zip! Web Services Web Services Nov 26, 2002 Nov 26, 2002 Topics Topics HTTP Serving static content Serving dynamic content


slide-1
SLIDE 1

Web Services Nov 26, 2002 Web Services Nov 26, 2002

Topics Topics

  • HTTP
  • Serving static content
  • Serving dynamic content
✁✄✂✄☎✝✆✄✆✟✞✝✠☛✡✌☞✍☞☛✎

15-213

“The course that gives CMU its Zip!”

slide-2
SLIDE 2

– 2 – 15-213, F’02

Web History Web History

1945: 1945:

  • Vannevar Bush, “As we may think”, Atlantic Monthly, July,

1945.

Describes the idea of a distributed hypertext system. A “memex” that mimics the “web of trails” in our minds.

1989: 1989:

  • Tim Berners-Lee (CERN) writes internal proposal to develop

a distributed hypertext system.

Connects “a web of notes with links.” Intended to help CERN physicists in large projects share and manage information

1990: 1990:

  • Tim BL writes a graphical browser for Next machines.
slide-3
SLIDE 3

– 3 – 15-213, F’02

Web History (cont) Web History (cont)

1992 1992

  • NCSA server released
  • 26 WWW servers worldwide

1993 1993

  • Marc Andreessen releases first version of NCSA Mosaic

browser

  • Mosaic version released for (Windows, Mac, Unix).
  • Web (port 80) traffic at 1% of NSFNET backbone traffic.
  • Over 200 WWW servers worldwide.

1994 1994

  • Andreessen and colleagues leave NCSA to form "Mosaic

Communications Corp" (now Netscape).

slide-4
SLIDE 4

– 4 – 15-213, F’02

Internet Hosts Internet Hosts

slide-5
SLIDE 5

– 5 – 15-213, F’02

Web Servers Web Servers

Web server

✏✒✑✓✑✓✔ ✕☛✖✓✗✓✘✓✖✒✙✓✚ ✏✒✑✓✑✓✔ ✕☛✖✒✙✝✛✢✜☛✣✒✙☛✖ ✤✦✥ ✜☛✣✒✚☛✖✓✣✒✚✒✧

Clients and servers Clients and servers communicate using the communicate using the HyperText HyperText Transfer Transfer Protocol (HTTP) Protocol (HTTP)

Client and server establish TCP connection

Client requests content

Server responds with requested content

Client and server close connection (usually)

Current version is HTTP/1.1 Current version is HTTP/1.1

RFC 2616, June, 1999. Web client (browser)

slide-6
SLIDE 6

– 6 – 15-213, F’02

Web Content Web Content

Web servers return Web servers return content content to clients to clients

  • content: a sequence of bytes with an associated MIME

(Multipurpose Internet Mail Extensions) type

Example MIME types Example MIME types

  • ✩✫✪✭✬✮✩✰✯✲✱✮✩✴✳✮✵

HTML document

  • ✩✫✪✭✬✮✩✰✯✲✶✷✵✰✸✰✹✫✺

Unformatted text

  • ✸✫✶✰✶✷✵✰✹✰✻✰✸✷✩✫✹✰✼✽✺✮✯✲✶✷✼✷✾✰✩✰✾✫✻✰✿✰✹✫✶❀✩ Postcript document
  • ✹✲✳❁✸✰❂✰✪✷✯✫❂✰✹✷❃

Binary image encoded in GIF format

  • ✹✲✳❁✸✰❂✰✪✷✯✰❄✲✶✷✪✰❂

Binary image encoded in JPEG format

slide-7
SLIDE 7

– 7 – 15-213, F’02

Static and Dynamic Content Static and Dynamic Content

The content returned in HTTP responses can be either The content returned in HTTP responses can be either static static or

  • r dynamic

dynamic. .

  • Static content: content stored in files and retrieved in

response to an HTTP request

Examples: HTML files, images, audio clips.

  • Dynamic content: content produced on-the-fly in response to

an HTTP request

Example: content produced by a program executed by the server on behalf of the client.

Bottom line: Bottom line: All Web content is associated with a file All Web content is associated with a file that is managed by the server. that is managed by the server.

slide-8
SLIDE 8

– 8 – 15-213, F’02

URLs URLs

Each file managed by a server has a unique name called a Each file managed by a server has a unique name called a URL (Universal Resource Locator) URL (Universal Resource Locator) URLs for static content: URLs for static content:

  • ✱✮✩✰✩✲✶
❅✴✯❆✯✲❇✰❇✰❇ ❈❉✻✷✾❊❈❉✻✲✳✷❋ ❈❉✪✰●✫❋ ❅✴❍✰■✰✯✫✹✫✺✷●✰✪✫✬ ❈❏✱✮✩✴✳✮✵
  • ✱✮✩✰✩✲✶
❅❑✯✰✯✲❇✰❇✰❇ ❈❉✻✷✾❊❈❉✻✲✳✷❋ ❈❉✪✰●✫❋✮✯✫✹✫✺✷●✰✪✫✬ ❈❏✱✮✩✴✳✮✵
  • ✱✮✩✰✩✲✶
❅✴✯✰✯✲❇✰❇✰❇ ❈❉✻✷✾❊❈❉✻✲✳✷❋ ❈❉✪✰●✫❋

Identifies a file called

▲ ✣✓▼✓✖✓◆P❖✦◗✒✚✝❘✢❙❯❚ managed by a Web server at ❱✓❱✓❱ ❖ ✥ ✙❲❖ ✥ ❘✒✘❳❖✦✖✓▼✓✘ that is listening on port 80.

URLs for dynamic content: URLs for dynamic content:

  • ✱✮✩✰✩✲✶
❅✴✯✰✯✲❇✰❇✰❇ ❈❉✻✷✾❊❈❉✻✲✳✷❋ ❈❉✪✰●✫❋ ❅✴❍✰■✰■✰■✰✯✫✻✰❂✰✹✷❨✴❩✮✹✫✺✮✯✫✸✰●✰●✰✪✰✿✷❬✰❭✫❪✷■✰■✰■✰❫✫❴✷❭✫❵

Identifies an executable file called

❛ ▼✓▼✓✖✒✕ , managed by a Web

server at

❱✓❱✓❱ ❖ ✥ ✙❁❖ ✥ ❘✒✘❜❖✦✖✓▼✓✘ that is listening on port 8000, that

should be called with two argument strings:

❝✓❞✓❡✓❡✓❡ and ❢✓❝✓❣ .
slide-9
SLIDE 9

– 9 – 15-213, F’02

How Clients and Servers Use URLs How Clients and Servers Use URLs

Example URL: Example URL: Clients use Clients use prefix prefix ( ( ) to infer: ) to infer:

  • What kind of server to contact (Web server)
  • Where the server is (
❇✰❇✰❇ ❈❉✸✰✼✰✵ ❈❉✻✰✼✲✳ )
  • What port it is listening on (80)

Servers use Servers use suffix suffix ( ( ) to: ) to:

  • Determine if request is for static or dynamic content.

No hard and fast rules for this. Convention: executables reside in

✥☛❤ ▲❥✐✄❦✢▲ ✣

directory

  • Find file on file system.

Initial “

❧ ” in suffix denotes home directory for requested

content. Minimal suffix is “

❧ ”, which all servers expand to some default

home page (e.g., ▲

✣✓▼✓✖✓◆P❖✦◗✒✚✝❘✢❙ ).
slide-10
SLIDE 10

– 10 – 15-213, F’02

Anatomy of an HTTP Transaction Anatomy of an HTTP Transaction

♠✴♥✲♦❉♣rq s❉t✴✉❉✈✲t✲s ✇✴✇✴✇✰①③②✴④✴✉⑤①⑦⑥✴④❏⑧ ⑨✴⑩

Client: open connection to server

❶✲❷❉❸ ♦❉♥✴❹ ❺✴❻✴❼✰❽⑦❾✴❿✴❿✰❽⑦❾✴➀✲➁✫❽⑦❺✴➂✰❽r❽✴❽

Telnet prints 3 lines to the terminal

➃✴➄ ♥✴♥✴➅✲➆✴➇❉➅r➈ ➇ ➄ ➉✴➄✲➊ ❽⑦➆ ➄❉➋ ❽ ➌✲➍ ➆ ➉❉➎ ➅ ➆❉➏ ➉ ❷ ➉ ➆✴➇❉➅ ❷ ♦ ➍ ➐⑦➑✲➒✫➐ ❽ ➓ ➌✴❶ ➔ →✴❶✴❶✲➣✴➔ ❾✰❽⑦❾

Client: request line

➏ ➄ ➍ ➇✰↔ ↕✴↕✴↕✮❽ ➉✴➄✲➊ ❽⑦➆ ➄❉➋

Client: required HTTP/1.1 HOST header Client: empty line terminates headers

❽ →✴❶✴❶✲➣✴➔ ❾✰❽⑦❻ ❺✴❻✴❻ ➙✴➛ ➜✫➝❏➜✲➌✲➞❏➟ ➅ ❷✴➍ ♦ ➄ ♥✷↔ ❾✰❽⑦❻

Server: followed by five response headers

➠ ➉ ➇❉➅✷↔ ➜ ➄ ♥✷➡ ❻✴❿ ➢ ➉ ♥ ❺✴❻✴❻✴❾ ❻✴➀✰↔⑦❼✲➤✫↔⑦➀✴❺ ➓ ➜❥❶ ➥ ➅ ❷❉➦ ➅ ❷ ↔ ➧ ➉ ➦ ♦ ➥ ➅ ❷❉➦ ➅ ❷➨➔ ❺✰❽⑦❻ ➩✲➙✴➫ ➍ ➅ ❷❉➦ ➅ ❷➨➔ ❺✰❽⑦➂✰❽⑦➂ ➃✴➄ ♥✲➇❉➅✴♥✲➇ ➞❉❶✴❸ ➎ ➅✷↔ ➇❉➅✴♣✲➇ ➔ ➏✲➇ ➋✽➊

Server: expect HTML in the response body

➃✴➄ ♥✲➇❉➅✴♥✲➇ ➞ ➫✴➅✴♥✴❹✲➇❉➏✷↔ ➀✴❺✴❻✲➤❉❺

Server: expect 42,092 bytes in the resp body Server: empty line (“

➭⑦➯✰➭ ✈ ”) terminates hdrs ➲ ➏✲➇ ➋✫➊ q

Server: first HTML line in response body

❽✴❽✴❽

Server: 766 lines of HTML not shown.

➲ ➔ ➏✲➇ ➋✫➊ q

Server: last HTML line in response body

➃✴➄ ♥✴♥✴➅✲➆✴➇✴♦ ➄ ♥ ➆ ➊❉➄ ➍ ➅✴➈ ➳ ❸ ➵ ➄ ❷ ➅✲♦❉❹✴♥ ➏ ➄ ➍ ➇✰❽

Server: closes connection

♠✴♥✲♦❉♣✴q

Client: closes connection and terminates

slide-11
SLIDE 11

– 11 – 15-213, F’02

HTTP Requests HTTP Requests

HTTP request is a HTTP request is a request line request line, followed by zero or , followed by zero or more more request headers request headers Request line: Request line:

  • ➸✷➺✷✪✰✿➻✾✫✹✰✼✫✺➻➼ is HTTP version of request (
➽✷➾✰➾✰➚ ✯⑤❭❊❈✴■ or ➽➪➾✰➾✰➚ ✯✰❭❊❈✴❭ )
  • ➸✷❋✷✿⑤✹✰➼ is typically URL for proxies, URL suffix for servers.
  • ➸✰✳✮✪➻✩✲✱✷✼⑤●✰➼

is either

➶✽➹✷➾ ➘ ➚✫➴➻➷✰➾ ➘ ➴✷➚⑤➾✷➬✲➴✰➮➻➷ ➘ ➽✰➹✫➱➻✃ ➘ ➚✫❐✷➾ ➘ ✃✰➹✷❒✫➹➻➾✫➹ ➘
  • r
➾✽❮✫➱✮❰✽➹ ❈
slide-12
SLIDE 12

– 12 – 15-213, F’02

HTTP Requests (cont) HTTP Requests (cont)

HTTP methods: HTTP methods:

  • ➶✫➹✷➾ : Retrieve static or dynamic content

Arguments for dynamic content are in URI Workhorse method (99% of requests)

  • ➚✫➴✷➷✰➾ : Retrieve dynamic content

Arguments for dynamic content are in the request body

  • ➴✷➚✰➾✷➬Ï➴✰➮✷➷ : Get server or file attributes
  • ➽✰➹✫➱✷✃ : Like
➶✫➹➻➾ but no data in response body
  • ➚✫❐✷➾ : Write a file to the server!
  • ✃✰➹✷❒✽➹✷➾✫➹ : Delete a file on the server!
  • ➾✫❮✫➱✮❰✽➹ : Echo request in response body

Useful for debugging.

slide-13
SLIDE 13

– 13 – 15-213, F’02

HTTP Requests (cont) HTTP Requests (cont)

Request headers: Request headers: > >

  • Provide additional information to the server.

Major differences between HTTP/1.1 and HTTP/1.0 Major differences between HTTP/1.1 and HTTP/1.0

  • HTTP/1.0 uses a new connection for each transaction.
  • HTTP/1.1 also supports persistent connections

multiple transactions over the same connection

Ð ✜☛✣✓✣✓✖ ✥ ✚ ▲ ✜☛✣PÑ Ò✓✖✓✖☛✛ ✐③Ó ❙ ▲☛Ô ✖
  • HTTP/1.1 requires
➽✰➴➻➷✰➾ header ✏✒✜✓✙✓✚❲Ñ Õ ▲ ✚✓✚☛Ö✓◗ ❛ ❱ Õ×❖ ✥ ❘ ✥ ❙Ø❖ ✥ ✙❁❖ ✥ ❘✒✘❜❖✦✖✓▼✓✘
  • HTTP/1.1 adds additional support for caching
slide-14
SLIDE 14

– 14 – 15-213, F’02

HTTP Responses HTTP Responses

HTTP response is a HTTP response is a response line response line followed by zero or followed by zero or more more response headers response headers. . Response line: Response line:

  • <version> is HTTP version of the response.
  • <status code> is numeric status.
  • <status msg> is corresponding English text.

200 OK Request was handled without error 403 Forbidden Server lacks permission to access file 404 Not found Server couldn’t find the file.

Response headers: Response headers:

  • Provide additional information about response
✼✽✺✮✩✫✪✽✺✮✩✰❨ ➾✫Ù ✶✷✪ ❅

MIME type of content in response body.

✼✽✺✮✩✫✪✫✺✮✩⑤❨ ❒ ✪✫✺➻❂✷✩✲✱ ❅

Length of content in response body.

slide-15
SLIDE 15

– 15 – 15-213, F’02

Request to Apache Server From IE Browser Request to Apache Server From IE Browser

➓ ➌✴❶ ➔ ➇Ú➅ ➍ ➇✰❽Û➏✲➇ ➋✫➊ →✴❶✴❶✲➣✴➔ ❾✰❽⑦❾ ➩✫➆✴➆Ú➅ ➎ ➇✰↔ Ü ➔ Ü ➩✫➆✴➆❉➅ ➎ ➇ ➞ ➫ ➉ ♥✴❹✴♠ ➉ ❹✴➅✷↔ ➅✴♥ ➞ ♠ ➍ ➩✫➆✴➆❉➅ ➎ ➇ ➞❉➌ ♥✲➆ ➄ ➈✲♦❉♥✴❹✷↔ ❹✲Ý✴♦ ➎ ➡ ➈✴➅ ➵ ➊❉➉ ➇❉➅ Þ✲➍ ➅ ❷✴➞ ➩✲❹✴➅✴♥✲➇✰↔ ➜ ➄ Ý✴♦ ➊✴➊❉➉ ➔ ➀✰❽⑦❻ ßÛ➆ ➄❉➋✴➎✲➉ ➇✴♦❏➳ ➊ ➅✰à ➜ ➥ ➝❉➌ ➀✰❽⑦❻✴❾✫à á✫♦❉♥✴➈ ➄ ↕ ➍ ➤❉❿✲â → ➄ ➍ ➇✰↔ ➅✴♠ ❷ ➄ ❽ã➅✲➆ ➄❉➋ ❽⑦➆ ➋ ♠✷❽Û➅✴➈✴♠ ➃✴➄ ♥✴♥✴➅✲➆r➇✴♦ ➄ ♥✷↔ ➛✴➅✴➅ ➎ ➞ ➩ ➊ ♦ ➦ ➅ ➃✴ä ➫rå ßÛæ ❷ æ❉♥✫â
slide-16
SLIDE 16

– 16 – 15-213, F’02

Response From Apache Server Response From Apache Server

→✴❶✴❶✲➣r➔ ❾✰❽⑦❾ ❺✴❻✴❻ ➙✴➛ ➠ ➉ ➇❉➅✷↔ ❶ ➏✴♠➻➡ ❺✴❺ ➢❉♠ ➊ ❾✲➤✴➤✴➤ ❻✴➀✰↔⑦❻✴❺✰↔⑦❾✴❼ ➓ ➜❥❶ ➥ ➅ ❷❉➦ ➅ ❷ ↔ ➩ ➎✲➉ ➆❉➏✴➅ ➔ ❾✰❽⑦➂✰❽⑦➂ ç✴➅✴♥ ➞ ➥✴➥ ➫ ➔ ❾✰❽⑦❺✴❿ ß Þ ♥✲♦❉♣✫â ➫ ➉ ➍ ➇ ➞❏➜ ➄ ➈✲♦ ➵ ♦❉➅✴➈✷↔ ❶ ➏✴♠✷➡ ❺✴❺ ➢❉♠ ➊ ❾✲➤✴➤✴➤ ❻✴➂è↔⑦➂✴➂✰↔⑦❺✴❾ ➓ ➜✲❶ ➌✴❶ ➉ ❹✷↔ éÚ➀✴❿❏➳✴➳✫❺ ➞ ➀ ➵✴➞ ➂✴ê✲➤✴➁✴➤❉❾✴❻✴❾✲é ➩✫➆✴➆❉➅ ➎ ➇ ➞ ä✴➉ ♥✴❹✴➅ ➍ ↔ ➳ ❸ ➇❉➅ ➍ ➃✴➄ ♥✲➇❉➅r♥✲➇ ➞ ➫✴➅✴♥✴❹✲➇❉➏✷↔ ê✲➤ ➛✴➅✴➅ ➎ ➞ ➩ ➊ ♦ ➦ ➅✷↔ ➇✴♦ ➋ ➅ ➄ ♠✲➇❉ë✲❾✴❼✰➡ ➋✲➉ ♣✴ë✲❾✴❻✴❻ ➃✴➄ ♥✴♥✴➅✲➆r➇✴♦ ➄ ♥✷↔ ➛✴➅✴➅ ➎ ➞ ➩ ➊ ♦ ➦ ➅ ➃✴➄ ♥✲➇❉➅✴♥Ï➇ ➞❉❶✴❸ ➎ ➅✷↔ ➇❉➅✴♣✲➇ ➔ ➏✲➇ ➋✫➊ ➃rä ➫✴å ➲ ➏Ï➇ ➋✫➊ q ➲ ➏✴➅ ➉ ➈✴q ➲ ➇✴♦r➇ ➊ ➅✴q ❶ ➅ ➍ ➇ ➎✲➉ ❹✴➅ ➲ ➔ ➇✴♦✴➇ ➊ ➅✴q ➲ ➔ ➏✴➅ ➉ ➈✴q ➲ ➳ ➄ ➈ ❸ q ➲ ➏✲❾❉q ❶ ➅ ➍ ➇ ➎✲➉ ❹✴➅ ➲ ➔ ➏✲❾❉q ➲ ➔ ➏✲➇ ➋✫➊ q
slide-17
SLIDE 17

– 17 – 15-213, F’02

Serving Dynamic Content Serving Dynamic Content

Client Server

Client sends request to Client sends request to server. server. If request URI contains the If request URI contains the string “ string “ ”, then ”, then the server assumes that the server assumes that the request is for the request is for dynamic content. dynamic content.

ì✓í ✑ ❧ ✥☛❤ ▲✭✐✄❦✢▲ ✣ ❧ ✖✓✣ Ô ❖î✛✢❙ ✏✒✑✓✑✓✔ ❧✓❝ ❖ ❝
slide-18
SLIDE 18

– 18 – 15-213, F’02

Serving Dynamic Content (cont) Serving Dynamic Content (cont)

Client Server

The server creates a child The server creates a child process and runs the process and runs the program identified by the program identified by the URI in that process URI in that process

✖✓✣ Ô ❖î✛✢❙ ï ✜✓✕☛Õ ❧ ✖✓◆✓✖ ✥
slide-19
SLIDE 19

– 19 – 15-213, F’02

Serving Dynamic Content (cont) Serving Dynamic Content (cont)

Client Server

The child runs and The child runs and generates the dynamic generates the dynamic content. content. The server captures the The server captures the content of the child and content of the child and forwards it without forwards it without modification to the client modification to the client

✖✓✣ Ô ❖î✛✢❙

Content Content

slide-20
SLIDE 20

– 20 – 15-213, F’02

Issues in Serving Dynamic Content Issues in Serving Dynamic Content

How does the client pass program How does the client pass program arguments to the server? arguments to the server? How does the server pass these How does the server pass these arguments to the child? arguments to the child? How does the server pass other How does the server pass other info relevant to the request to info relevant to the request to the child? the child? How does the server capture the How does the server capture the content produced by the child? content produced by the child? These issues are addressed by the These issues are addressed by the Common Gateway Interface (CGI) Common Gateway Interface (CGI) specification. specification.

Client Server Content Content Request Create

✖✓✣ Ô ❖î✛✢❙
slide-21
SLIDE 21

– 21 – 15-213, F’02

CGI CGI

Because the children are written according to the CGI Because the children are written according to the CGI spec, they are often called spec, they are often called CGI programs CGI programs. . Because many CGI programs are written in Because many CGI programs are written in Perl Perl, they , they are often called are often called CGI scripts CGI scripts. . However, CGI really defines a simple standard for However, CGI really defines a simple standard for transferring information between the client (browser), transferring information between the client (browser), the server, and the child process. the server, and the child process.

slide-22
SLIDE 22

– 22 – 15-213, F’02

add.com: THE Internet addition portal! add.com: THE Internet addition portal!

Ever need to add two numbers together and you just Ever need to add two numbers together and you just can’t find your calculator? can’t find your calculator? Try Dr. Dave’s addition service at “add.com: THE Try Dr. Dave’s addition service at “add.com: THE Internet addition portal!” Internet addition portal!”

  • Takes as input the two numbers you want to add together.
  • Returns their sum in a tasteful personalized message.

After the IPO we’ll expand to multiplication! After the IPO we’ll expand to multiplication!

slide-23
SLIDE 23

– 23 – 15-213, F’02

The add.com Experience The add.com Experience

input URL Output page host port CGI program args

slide-24
SLIDE 24

– 24 – 15-213, F’02

Serving Dynamic Content With GET Serving Dynamic Content With GET

Question: Question: How does the client pass arguments to the How does the client pass arguments to the server? server? Answer: Answer: The arguments are appended to the URI The arguments are appended to the URI Can be encoded directly in a URL typed to a browser Can be encoded directly in a URL typed to a browser

  • r a URL in an HTML link
  • r a URL in an HTML link
  • ✱✮✩✰✩✲✶
❅❑✯✰✯✫✸✰●✰● ❈❉✻✰✼✲✳❊✯✫✻✰❂✰✹✷❨✴❩✮✹✫✺✮✯✫✸✰●✰●✰✪✰✿✷❬✰❭✰❫✫❴
  • ✸✰●✰●✰✪⑤✿ is the CGI program on the server that will do the

addition.

  • argument list starts with
ð ❬✰ñ
  • arguments separated by
ð ❫✰ñ
  • spaces represented by
ð✫ò ñ ✼⑤✿ ð⑤ó ❴✷■⑤ñ

Can also be generated by an HTML form Can also be generated by an HTML form

➲ ➵ ➄ ❷ ➋ ➋ ➅✲➇❉➏ ➄ ➈✴ë✴❹✴➅✲➇ ➉ ➆✴➇✴♦ ➄ ♥✴ë✫é❏➏✲➇✴➇ ➎ ↔ ➔✴➔ ➉ ➈ô➈✷❽⑦➆ ➄❉➋ ➔ ➆❉❹✲♦ ➞ ➳✫♦❉♥ ➔ ➎✲➄ ➍ ➇ ➉ ➈r➈✴➅ ❷ é❏q
slide-25
SLIDE 25

– 25 – 15-213, F’02

Serving Dynamic Content With GET Serving Dynamic Content With GET

URL: URL:

  • ✱✮✩✰✩✲✶
❅✴✯✰✯✫✸✰●✰● ❈❉✻✰✼✲✳❊✯✫✻✰❂✰✹✷❨✴❩✮✹✫✺✮✯✫✸✰●✰●✰✪✰✿✷❬✰❭✰❫✫❴

Result displayed on browser: Result displayed on browser: Welcome to add.com: THE Internet addition portal. The answer is: 1 + 2 = 3 Thanks for visiting! Tell your friends.

slide-26
SLIDE 26

– 26 – 15-213, F’02

Serving Dynamic Content With GET Serving Dynamic Content With GET

Question Question: How does the server pass these : How does the server pass these arguments to the child? arguments to the child? Answer: Answer: In environment variable QUERY_STRING In environment variable QUERY_STRING

  • A single string containing everything after the “?”
  • For add.com:
õ✰❐✰➹✰❮⑤ö✫÷✮➷✰➾✫❮✮➬✲➮✷➶ = “ ❭✰❫✫❴ ” ➔ Ü ➆❉➏✲♦ ➊ ➈ ➆ ➄ ➈✴➅ ➇❉➏ ➉ ➇ ➉ ➆✴➆❉➅ ➍✴➍ ➅ ➍ ➇❉➏✴➅ ➉ ❷ ❹✴♠ ➋ ➅✴♥✲➇ ➊ ♦ ➍ ➇ Ü ➔ ♦ ➵ ß✴ßø➳✲♠ ➵ ë ❹✴➅✲➇❉➅✴♥ ➦ ß⑦é❏ù Þ✴➌ ä✴ú❉û✫➥ ❶ ä ➝ ➧ ➓ é✴â✴â ë✴ë ➧ Þ ➫✴➫✫â ü ➅✴♣✲♦✴➇✷ßÛ❾✲â✲à ý ➔ Ü ➅✴♣✲➇ ❷ ➉ ➆✴➇ ➉ ❷ ❹✲❾ ➉ ♥✴➈ ➉ ❷ ❹✲❺ ➵✴❷ ➄❉➋ ➳✲♠ ➵ ➉ ♥✴➈ ➆ ➄ ♥ ➦ ➅ ❷ ➇ Ü ➔ ❽✴❽✴❽ ♥✲❾ ë ➉ ➇ ➄ ♦✷ß ➉ ❷ ❹✲❾✲â✲à ♥✲❺ ë ➉ ➇ ➄ ♦✷ß ➉ ❷ ❹✲❺✲â✲à
slide-27
SLIDE 27

– 27 – 15-213, F’02

Serving Dynamic Content With GET Serving Dynamic Content With GET

Question: Question: How does the server pass other info relevant How does the server pass other info relevant to the request to the child? to the request to the child? Answer: Answer: In a collection of environment variables In a collection of environment variables defined by the CGI spec. defined by the CGI spec.

slide-28
SLIDE 28

– 28 – 15-213, F’02

Some CGI Environment Variables Some CGI Environment Variables

General General

  • ➷✫➹✰❮✫þ✷➹✰❮✫÷✮➷✫➴✷ÿ✰➾✁✰➱✷❮✰➹
  • ➷✫➹✰❮✫þ✷➹✰❮✫÷✷➮✫➱✄✂✷➹
  • ➶✲➱✮➾✫➹☎✰➱✷ö✫÷❊➬✲➮✷➾✫➹✰❮✷ÿÏ➱✮❰✫➹ (CGI version)

Request-specific Request-specific

  • ➷✫➹✰❮✫þ✷➹✰❮✫÷✮➚✫➴✰❮✷➾
  • ❮✰➹✰õ✰❐✰➹✷➷✰➾✲÷✄✂✷➹✷➾✫➽✰➴✰✃ (
➶✫➹✷➾ , ➚✫➴✷➷✰➾ , etc)
  • õ✰❐✰➹⑤❮✰ö✫÷✮➷✰➾✫❮✮➬Ï➮✷➶ (contains
➶✫➹✷➾ args)
  • ❮✰➹✆✂✷➴➻➾✫➹✫÷✷➽✰➴✷➷✰➾ (domain name of client)
  • ❮✰➹☎✂✷➴✷➾✫➹✫÷⑤➱✷✃✰✃✰❮ (IP address of client)
  • ❰✫➴✰➮✷➾✫➹✰➮✷➾✲÷✮➾✫ö✷➚✫➹ (for
➚✫➴✷➷✰➾ , type of data in message body, e.g., ✩✫✪✫✬✮✩✰✯✲✱✮✩✴✳✮✵ )
  • ❰✫➴✰➮✷➾✫➹✰➮✷➾✲÷✮❒✫➹⑤➮✷➶✰➾✫➽ (length in bytes)
slide-29
SLIDE 29

– 29 – 15-213, F’02

Some CGI Environment Variables Some CGI Environment Variables

In addition, the value of each header of type In addition, the value of each header of type type type received from the client is placed in environment received from the client is placed in environment variable variable type type

  • Examples:
✏✒✑✓✑✓✔✞✝ Ó Ð✓Ð✓í ✔✓✑ ✏✒✑✓✑✓✔✞✝✒✏✠✟☛✡✓✑ ✏✒✑✓✑✓✔✞✝☛☞☛✡ í✠✌ ✝ Ó ì✓í✎✍ ✑ (any “-” is changed to “_”)
slide-30
SLIDE 30

– 30 – 15-213, F’02

Serving Dynamic Content With GET Serving Dynamic Content With GET

Question: Question: How does the server capture the content produced by the How does the server capture the content produced by the child? child? Answer: Answer: The child generates its output on The child generates its output on

✾✰✩✫●✰✼✫❋✮✩ ✾✰✩✫●✰✼✫❋✮✩ . Server uses

. Server uses

  • ✫❋✰✶✷❴
  • ✭❋✰✶✷❴

to redirect to redirect

✾✰✩✫●❆✼✫❋✮✩ ✾✰✩✫●✰✼✫❋✮✩

to its connected socket. to its connected socket.

Notice that only the child knows the type and size of the content. Thus the child (not the server) must generate the corresponding headers.

➔ Ü ➆❉➏✲♦ ➊ ➈ ❹✴➅✴♥✴➅ ❷ ➉ ➇❉➅ ➍ ➇❉➏✴➅ ❷ ➅ ➍ ♠ ➊ ➇ ➍ ➇ ❷ ♦❉♥✴❹ Ü ➔ ➍ ➎ ❷ ♦❉♥✲➇ ➵ ßÛ➆ ➄ ♥✲➇❉➅✴♥✲➇✰➡ é⑦á✲➅ ➊ ➆ ➄❉➋ ➅ ➇ ➄ ➉ ➈✴➈✷❽⑦➆ ➄❉➋ ↔ ❶✴→✴➌ ➝ ♥✲➇❉➅ ❷ ♥✴➅✲➇ ➉ ➈✴➈✲♦✴➇✴♦ ➄ ♥ ➎✲➄ ❷ ➇ ➉✲➊ æ ➲ ➎ q ❶ ➏✴➅ ➉ ♥ ➍ ↕✲➅ ❷ ♦ ➍ ↔ ✏❉➈ ✑ ✏ ➈ ë ✏❉➈✲æ ➲ ➎ q ❶ ➏ ➉ ♥✓✒ ➍ ➵ ➄ ❷ ➦ ♦ ➍ ♦✴➇✴♦❉♥✴❹✕✔⑦æ ❷ æ❉♥✫é✽➡ ♥✲❾✰➡ ♥✲❺✰➡ ♥✲❾✖✑✴♥✲❺✲â✲à ➔ Ü ➆❉➏✲♦ ➊ ➈ ❹✴➅✴♥✴➅ ❷ ➉ ➇❉➅ ➍ ➇❉➏✴➅ ➏✴➅ ➉ ➈✴➅ ❷✴➍ ➉ ♥✴➈ ➈ ❸ ♥ ➉❉➋ ♦✴➆ ➆ ➄ ♥Ï➇❉➅✴♥✲➇ Ü ➔ ➎ ❷ ♦❉♥✲➇ ➵ ß⑦é ➃✴➄ ♥✲➇❉➅r♥✲➇ ➞ ➊ ➅✴♥✴❹✲➇❉➏✷↔ ✏❉➈✲æ ❷ æ❉♥✫é✫➡ ➍ ➇ ❷ ➊ ➅✴♥✮ßÛ➆ ➄ ♥✲➇Ú➅✴♥✲➇✲â✴â✲à ➎ ❷ ♦❉♥✲➇ ➵ ß⑦é ➃✴➄ ♥✲➇❉➅✴♥✲➇ ➞ ➇ ❸ ➎ ➅✷↔ ➇❉➅✴♣✲➇ ➔ ➏✲➇ ➋✫➊ æ ❷ æ❉♥✫é✴â✲à ➎ ❷ ♦❉♥✲➇ ➵ ß⑦é❉æ ❷ æ❉♥✫é✴â✲à ➎ ❷ ♦❉♥✲➇ ➵ ß⑦é✖✏ ➍ é✫➡ ➆ ➄ ♥✲➇❉➅✴♥✲➇✲â✲à
slide-31
SLIDE 31

– 31 – 15-213, F’02

Serving Dynamic Content With GET Serving Dynamic Content With GET

➳ ➉ ➍✴➍ q ❽ ➔ ➇✴♦❉♥ ❸ ❿✴❻✴❻✴❻ ➓ ➌✴❶ ➔ ➆❉❹✲♦ ➞ ➳✫♦❉♥ ➔ ➉ ➈✴➈✴➅ ❷✁✗ ❾✁✘❉❺ →✴❶✴❶✲➣✴➔ ❾✰❽⑦❾ → ➄ ➍ ➇✰↔ ➳ ➉ ➍✴➍ ❽③➆ ➋ ➆ ➊ ❽⑦➆ ➍ ❽⑦➆ ➋ ♠✷❽Û➅✴➈✴♠ ↔⑦❿✴❻✴❻✴❻ ➲ ➃✴ä ➫rå✴q ✒✲♦✴➇✴➇ ❸ ➏ ➉ ↕✁✒➨q ➇❉➅ ➊ ♥✴➅✲➇ ➳ ➉ ➍✴➍ ❿✴❻✴❻✴❻ ❶✲❷❉❸ ♦❉♥✴❹ ❾✴❺✴❿✰❽⑦❺✰❽⑦❺r❺✴❺✰❽⑦❿✴❼✰❽✴❽✴❽ ➃✴➄ ♥✴♥✴➅✲➆✴➇❉➅✴➈ ➇ ➄ ç❉➩ ➥✴➥ ❽ ➃ ➜ ➃ ➫➻❽ ➃✲➥ ❽ ➃ ➜✲Þ ❽ ➌✴➠✴Þ ❽ ➌✲➍ ➆ ➉❉➎ ➅ ➆❉➏ ➉ ❷ ➉ ➆✴➇❉➅ ❷ ♦ ➍ ➐⑦➑✲➒✫➐ ❽ ➓ ➌✴❶ ➔ ➆❉❹✲♦ ➞ ➳✫♦❉♥ ➔ ➉ ➈✴➈✴➅ ❷✁✗ ❾✁✘❉❺ →✴❶✴❶✲➣✴➔ ❾✰❽⑦❾ → ➄ ➍ ➇✰↔ ➳ ➉ ➍✴➍ ❽③➆ ➋ ➆ ➊ ❽⑦➆ ➍ ❽⑦➆ ➋ ♠✷❽Û➅✴➈✴♠ ↔⑦❿✴❻✴❻✴❻ ➲ ➃✴ä ➫rå✴q →✴❶✴❶✲➣✴➔ ❾✰❽⑦❾ ❺✴❻✴❻ ➙✴➛ ➥ ➅ ❷❉➦ ➅ ❷ ↔ ❶ ♦❉♥ ❸ á✲➅Ú➳ ➥ ➅ ❷❉➦ ➅ ❷ ➃✴➄ ♥✲➇❉➅✴♥✲➇ ➞ ➊ ➅✴♥✴❹Ï➇❉➏✷↔ ❾✴❻✴❺ ➃✴➄ ♥✲➇❉➅✴♥✲➇ ➞ ➇ ❸ ➎ ➅✷↔ ➇Ú➅✴♣✲➇ ➔ ➏✲➇ ➋✫➊ ➲ ➃✴ä ➫rå✴q á✲➅ ➊ ➆ ➄❉➋ ➅ ➇ ➄ ➉ ➈✴➈✷❽⑦➆ ➄❉➋ ↔ ❶✴→r➌ ➝ ♥✲➇❉➅ ❷ ♥✴➅✲➇ ➉ ➈✴➈✲♦✴➇✴♦ ➄ ♥ ➎✲➄ ❷ ➇ ➉✲➊ ❽ ➲ ➎ q ❶ ➏✴➅ ➉ ♥ ➍ ↕✲➅ ❷ ♦ ➍ ↔ ❾ ✑ ❺ ë ➂ ➲ ➎ q ❶ ➏ ➉ ♥✓✒ ➍ ➵ ➄ ❷ ➦ ♦ ➍ ♦✴➇✴♦❉♥✴❹✕✔ ➃✴➄ ♥✴♥✴➅✲➆✴➇✴♦ ➄ ♥ ➆ ➊❉➄ ➍ ➅✴➈ ➳ ❸ ➵ ➄ ❷ ➅✲♦❉❹✴♥ ➏ ➄ ➍ ➇✰❽ ✒✲♦✴➇✴➇ ❸ ➏ ➉ ↕✁✒➨q

HTTP request received by Tiny Web server HTTP request sent by client HTTP response generated by the server HTTP response generated by the CGI program

slide-32
SLIDE 32

– 32 – 15-213, F’02

Proxies Proxies

A A proxy proxy is an intermediary between a client and an is an intermediary between a client and an

  • rigin server
  • rigin server.

.

  • To the client, the proxy acts like a server.
  • To the server, the proxy acts like a client.

Client Proxy Origin Server

HTTP request HTTP request HTTP response HTTP response

slide-33
SLIDE 33

– 33 – 15-213, F’02

Why Proxies? Why Proxies?

Can perform useful functions as requests and Can perform useful functions as requests and responses pass by responses pass by

  • Examples: Caching, logging, anonymization

Client A Proxy cache Origin Server

Request

➵ ➄✴➄ ❽Û➏✲➇ ➋✫➊

Request

➵ ➄✴➄ ❽Û➏✲➇ ➋✫➊ ➵ ➄✴➄ ❽Û➏✲➇ ➋✫➊ ➵ ➄✴➄ ❽Û➏✲➇ ➋✫➊

Client B

Request

➵ ➄✴➄ ❽Û➏Ï➇ ➋✫➊ ➵ ➄✴➄ ❽Û➏✲➇ ➋✫➊

Fast inexpensive local network Slower more expensive global network

slide-34
SLIDE 34

– 34 – 15-213, F’02

For More Information For More Information

Study the Tiny Web server described in your text Study the Tiny Web server described in your text

  • Tiny is a sequential Web server.
  • Serves static and dynamic content to real browsers.

text files, HTML files, GIF and JPEG images.

  • 220 lines of commented C code.
  • Also comes with an implementation of the CGI script for the

add.com addition portal.