1 / 29

HTTP

HTTP. Introduction. Client-Server communication protocol Request-response Version 1.0 Stateless Version 1.1 added the ability to keep connections open virtual hosting etc. Request/Response. Request - Response Architecture Client makes request Server issues response General Structure

Download Presentation

HTTP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. HTTP

  2. Introduction • Client-Server communication protocol • Request-response • Version 1.0 • Stateless • Version 1.1 added • the ability to keep connections open • virtual hosting • etc

  3. Request/Response • Request - Response Architecture • Client makes request • Server issues response • General Structure • Start_Line<CRLF> • Message Header<CRLF> • <CRLF> • Message Body<CRLF>

  4. More Details • Start_line (Request or Response) • Request • Method<SP>Request-URI<SP>HTTP-Version<CRLF> • Response • HTTP-Version<SP>Status-code<SP>Response-Phrase<CRLF> • Message Header • Field_name:<SP>Field_value, Field_value • Message Body • Binary data

  5. HTTP Request Methods • GET – Retrieve the URL • POST – Give information to server • HEAD – Retrieve the headers for the URL • OPTIONS – Request available options • PUT – Store document at specified URL • DELETE – Delete specified URL • and many others……

  6. Typical Request • Version 1.0 • Version 1.1 GET /path/fiile.html HTTP/1.0 From: someuser@jmarshall.com User-Agent: HTTPTool/1.0 [blank line here] GET /path/fiile.html HTTP/1.1 Host: www.host1.com:80 [blank line here]

  7. The GET Method • Retrieves a URL • General case is very simple • Can send information along with URL • URL?name1=value1&name2=value2 • No Message Body GET /path/file.html?n=v HTTP/1.1 Host: www.host1.com:80 [blank line here]

  8. The POST Method • Sends information in the Message Body • Information is free format POST /path/script.cgi HTTP/1.0 From: frog@jmarshall.com User-Agent: HTTPTool/1.0 Content-Type: application/x-www-form-urlencoded Content-Length: 32 home=Cosby&favorite+flavor=flies

  9. URL Encoding • Convert all “unsafe” characters to %xx • xx is the ascii value of the character in hex • “unsafe” characters: = & % + nonprintables • Change all spaces to + • Use = and & to connect name value pairs • name1=val1&name2=val2&name3=val3 • Example: name is Lucy, neighbors are Fred & Ethel • Name=Lucy&neighbors=Fred+%26+Ethel

  10. The HTTP Response • Status-Line • HTTP-Version Status-Code Response-Phrase • Headers • Header-Name: value • Blank line • Message Body

  11. Typical Response HTTP/1.0 200 OK Date: Fri, 31 Dec 1999 23:59:59 GMT Content-Type: text/html Content-Length: 1354 <html> <body> <h1>Happy New Year!</h1> (more fiile contents) . . . </body> </html>

  12. Status Line • HTTP-Version Status-Code Response-Phrase • The HTTP version is in the format "HTTP/x.y". • The status code is meant to be computer-readable; the reason phrase is meant to be human-readable, and may vary. • The status code is a three-digit integer • 1xy indicates an informational message only • 2xy indicates success of some kind • 3xy redirects the client to another URL • 4xy indicates an error on the client's part • 5xy indicates an error on the server's part

  13. Some Status Codes • 200 OK • The request succeeded, and the resulting resource (e.g. file or script output) is returned in the message body • 404 Not Found • 301 Moved Permanently • 302 Moved Temporarily • 303 See Other(HTTP 1.1 only) • The resource has moved to another URL (given by the Location: response header), and should be automatically retrieved by the client. This is often used by a CGI script to redirect the browser to an existing file. • 500 Server Error

  14. Headers • Name value pairs • Header-Name: Header Value • Header-Name is not case sensitive • Header Value may be case sensitive • Any number of spaces or tabs after : • Lines beginning with space or tab are continuations of previous line

  15. Header Examples • Date: Fri, 31 Dec 1999 23:59:59 GMT • Content-Type: text/html • Content-Length: 1354 • From: snell@cs.byu.edu • Last-Modified: Fri, 31 Dec 1999 23:59:59 GMT • Server: Apache/2.3 • User-Agent: Mozilla/3.0Gold

  16. Message Body • Data sent after header lines • after blank line • Request Message Body • User entered data in POST • None for GET • Response Message Body • requested resource • header lines usually describe the data • Content-Type: text/html Mime types • Content-Length: 1234 size in bytes

  17. HTTP 1.1 • Additional Headers • Sockets stay open • Time-out connection default action, or • Connection: close header • Host: header is required • Host: www.servername.domain • Chunked Data • Transfer-Encoding: chunked • chunks followed by zero<crlf>, footers, blank line • chunks are: size<crlf>data

  18. Chunked Transfer HTTP/1.1 200 OK Date: Fri, 31 Dec 1999 23:59:59 GMT Content-Type: text/plain Transfer-Encoding: chunked 1a; ignore-stuff-here Abcdefghijklmnopqrstuvwxyz 10 1234567890abcdef 0 some-footer: some-value another-footer: another-value [blank line here]

  19. Cookies • A small piece of information stored on the client machine and returned to the server. • http headers • Cookie • Set-Cookie • 4 K bytes per cookie • 20 cookies per server or domain

  20. Set-Cookie (server side) Set-Cookie: name=value - URL encoded text [;EXPIRES=dateValue] - Wdy, DD-Mon-YY HH:MM:SS GMT [;DOMAIN=domainName] - valid domain name [;PATH=pathName] - path to send cookie [;SECURE] - transmitted only if communication is SSL

  21. Cookie (client-side) Cookie: name=value1; name=value2 All cookie name=value pairs that match the current path are sent.

  22. Cookie example • Client requests document and receives • Set-Cookie: cust=W_Coyote; path=/; • Client stores cookie • When client requests another URL below /, client sends • Cookie: cust=W_Coyote; • Server may set multiple cookies with different paths • Client returns all matching cookies

  23. Items to remember • When sending response • Headers first • Blank line • Size should match • From blank line - headers not included • Needs to be a full document • Look at access and error logs for help

  24. HTTP Architectures

  25. Common Gateway Interface (CGI) Web Server Client HTTP stdin stdout CGI Program or Script

  26. CGI • User requests URL • Server recognizes dynamic page • Usually by directory and/or file extension • Server spawns app • Passes arguments/message body via stdin • HTTP headers in environment variables • App passes results back to server via stdout • Server sends results to client

  27. CGI • Advantages • Easy/Simple • Substantial installed base • Can use any language available on server • Many free scripts (www.cgidir.com) • Disadvantages • Spawning overhead • Concurrent hits to page cause multiple copies of app to be launched • Many CGI apps use slow interpreted languages

  28. Optimization Java Servlets and JSP also follow this model Web Server Client HTTP Interpreter Script Apache modules php mod-perl java??

  29. Another Server Configuration Web Server Client HTTP Connector socket Why? Java Web Server

More Related