proxy lab recitation i monday nov 20, 2006. outline what is a http proxy? http tutorial –http...

14
Proxy Lab Recitation I Monday Nov 20, 2006

Upload: blake-dixon

Post on 03-Jan-2016

213 views

Category:

Documents


1 download

TRANSCRIPT

  • Proxy Lab Recitation IMonday Nov 20, 2006

  • OutlineWhat is a HTTP proxy?HTTP TutorialHTTP RequestHTTP ResponseSequential vs. concurrent proxiesCaching

  • What is a proxy?Why a proxy?Access control (allowed websites)Filtering (viruses, for example)Caching (multiple people request CNN)ClientServerProxyBrowserwww.google.com

  • Brief HTTP TutorialHyper-Text Transfer ProtocolProtocol spoken between a browser and a web-server

    From browser web-server: REQUESTGET http://www.google.com/ HTTP/1.0

    From web-server browser: RESPONSEHTTP 200 OKOther stuff

  • HTTP RequestGET http://csapp.cs.cmu.edu/simple.html HTTP/1.1Host: csapp.cs.cmu.eduUser-Agent: Mozilla/5.0 ... Accept: text/xml,application/xml ...Accept-Language: en-us,en;q=0.5 ...Accept-Encoding: gzip,deflate ...Request TypePathHostVersionAn empty line terminates a HTTP request

  • HTTP RequestGET http://csapp.cs.cmu.edu/simple.html HTTP/1.1Host: csapp.cs.cmu.eduUser-Agent: Mozilla/5.0 ... Accept: text/xml,application/xml ...Accept-Language: en-us,en;q=0.5 ...Accept-Encoding: gzip,deflate ...The Host header is optional in HTTP/1.0 but we recommend that it be always included

  • HTTP RequestGET http://csapp.cs.cmu.edu/simple.html HTTP/1.1Host: csapp.cs.cmu.eduUser-Agent: Mozilla/5.0 ... Accept: text/xml,application/xml ...Accept-Language: en-us,en;q=0.5 ...Accept-Encoding: gzip,deflate ...The User agent identifies the browser type. Some websites use it to determine what to send. And reject you if you sayyou use MyWeirdBrowser Proxy must send this and all other headers through

  • HTTP ResponseHTTP/1.1 200 OKDate: Mon, 20 Nov 2006 03:34:17 GMTServer: Apache/1.3.19 (Unix) Last-Modified: Mon, 28 Nov 2005 23:31:35 GMTContent-Length: 129Connection: Keep-AliveContent-Type: text/htmlStatusStatus indicates whether it was successful or not, if it is a redirect, etc.

    The complete response should be transparently sent back to the client by the proxy.

  • HTTP ResponseHTTP/1.1 200 OKDate: Mon, 20 Nov 2006 03:34:17 GMTServer: Apache/1.3.19 (Unix) Last-Modified: Mon, 28 Nov 2005 23:31:35 GMTContent-Length: 129Connection: Keep-AliveContent-Type: text/htmlThis field identifies how many bytes are there in the response.

    Not sent by all web-servers. DO NOT RELY ON IT !

  • Concurrent ProxyNeed to handle multiple requests simultaneouslyFrom different clientsFrom the same client E.g., each individual image in a HTML document needs to be requested separately

    Serving requests sequentially decreases throughput Server is waiting for I/O most of the timeThis time can be used to start serving other clientsMultiple outstanding requests

  • Concurrent Proxy Use threads for making proxy concurrentCreate one thread for each new client requestThe thread finishes and exists after serving the client requestUse pthread librarypthread_create(), pthread_detach(), etc.

    Can use select() as well for adding concurrencyMuch more difficult to get right

  • Caching ProxyMost geeks visit http://slashdot.org/ every 2 minutesWhy fetch the same content again and again?(If it doesnt change frequently)

    The proxy can cache responses Serve directly out of its cacheReduces latency, network-load

  • Caching: Implementation Issues Use the GET URL (host/path) to locate the appropriate cache entry

    THREAD SAFETYA single cache is accessed by multiple threadsEasy to create bugs: thread 1 is reading an entry, while thread 2 is deleting the same entry

  • General adviceUse RIO routinesrio_readnb, rio_readlinebBe very careful when you are reading line-by-line (HTTP request), versus just a stream of bytes (HTTP response)When to use strcpy() vs. memcpy() gethostbyname(), inet_ntoa() are not thread-safe!Path: sequential + concurrency + caching