webserver a web server is a program that, using the client/server model and the world wide...

24
WebServer A Web server is a program that, using the client/server model and the World Wide Web's Hypertext Transfer Protocol (HTTP), serves the files that form Web pages to Web users (whose computers contain HTTP clients that forward their requests). Every computer on the Internet that contains a Web site must have a Web server program.

Upload: reginald-greene

Post on 29-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: WebServer A Web server is a program that, using the client/server model and the World Wide Web's Hypertext Transfer Protocol (HTTP), serves the files that

WebServer

A Web server is a program that, using the client/server model and the World Wide Web's Hypertext Transfer Protocol (HTTP), serves the files that form Web pages to Web users (whose computers contain HTTP clients that forward their requests). Every computer on the Internet that contains a Web site must have a Web server program.

Page 2: WebServer A Web server is a program that, using the client/server model and the World Wide Web's Hypertext Transfer Protocol (HTTP), serves the files that

So what does a Web server do? It serves static content to a Web browser at a basic level. This

means that the Web server receives a request for a Web page such as http://www.vishal.com/index.html and maps that Uniform Resource Locator (URL) to a local file on the host server. In this case, the file

index.html

is somewhere on the host file system. The server then loads this file from disk and serves it out across the network to the user's Web browser. This entire exchange is mediated by the browser and server talking to each other using Hypertext Transfer Protocol (HTTP).

Page 3: WebServer A Web server is a program that, using the client/server model and the World Wide Web's Hypertext Transfer Protocol (HTTP), serves the files that
Page 4: WebServer A Web server is a program that, using the client/server model and the World Wide Web's Hypertext Transfer Protocol (HTTP), serves the files that

What Is HTTP, and How Does It Work? The Hypertext Transfer Protocol (HTTP) is an application-level

protocol.

HTTP allows an open-ended set of methods to be used to indicate the purpose of a request. It builds on the discipline of reference provided by the Uniform Resource Identifier (URI), as a location (URL)or name (URN), for indicating the resource on which a method is to be applied. Messages are passed in a format similar to that used by Internet Mail and the Multipurpose Internet Mail Extensions (MIME).

Page 5: WebServer A Web server is a program that, using the client/server model and the World Wide Web's Hypertext Transfer Protocol (HTTP), serves the files that

Overall Operation

The HTTP protocol is based on a request/response paradigm. A client establishes a connection with a server and sends a request to the server in the form of a request method, URI, and protocol version, followed by a MIME-like message containing request modifiers, client information, and possible body content. The server responds with a status line, including the message's protocol version and a success or error code, followed by a MIME-like message containing server information, entity metainformation, and possible body content.

Page 6: WebServer A Web server is a program that, using the client/server model and the World Wide Web's Hypertext Transfer Protocol (HTTP), serves the files that

Most HTTP communication is initiated by a user agent and consists of a request to be applied to a resource on some origin server. In the simplest case, this may be accomplished via a single connection (v) between the user agent (UA) and the origin server (O).

request chain ------------------------> UA -------------------v-------------------

------------O <----------------------- response chain

Page 7: WebServer A Web server is a program that, using the client/server model and the World Wide Web's Hypertext Transfer Protocol (HTTP), serves the files that

A more complicated situation occurs when one or more intermediaries are present in the request/response chain. There are three common forms of intermediary:

ProxyGatewayTunnel.

Page 8: WebServer A Web server is a program that, using the client/server model and the World Wide Web's Hypertext Transfer Protocol (HTTP), serves the files that

Proxy

An intermediary program which acts as both a server and a client for the purpose of making requests on behalf of other clients. Requests are serviced internally or by passing them, with possible translation, on to other servers. A proxy must interpret and, if necessary, rewrite a request message before forwarding it. Proxies are often used as client-side portals through network firewalls and as helper applications for handling requests via protocols not implemented by the user agent.

Page 9: WebServer A Web server is a program that, using the client/server model and the World Wide Web's Hypertext Transfer Protocol (HTTP), serves the files that

Gateway

A server which acts as an intermediary for some other server. Unlike a proxy, a gateway receives requests as if it were the origin server for the requested resource; the requesting client may not be aware that it is communicating with a gateway. Gateways are often used as server-side portals through network firewalls and as protocol translators for access to resources stored on non-HTTP systems.

Page 10: WebServer A Web server is a program that, using the client/server model and the World Wide Web's Hypertext Transfer Protocol (HTTP), serves the files that

Tunnel

A tunnel is an intermediary program which is acting as a blind relay between two connections. Once active, a tunnel is not considered a party to the HTTP communication, though the tunnel may have been initiated by an HTTP request. The tunnel ceases to exist when both ends of the relayed connections are closed. Tunnels are used when a portal is necessary and the intermediary cannot, or should not, interpret the relayed communication.

Page 11: WebServer A Web server is a program that, using the client/server model and the World Wide Web's Hypertext Transfer Protocol (HTTP), serves the files that

HTTP Message

Full-Request = Request-Line ;

*( General-Header;

| Request-Header ;

| Entity-Header ) ;

CRLF

[ Entity-Body ] ; Full-Response = Status-Line ;

*( General-Header ;

| Response-Header ;

| Entity-Header ) ;

CRLF

[ Entity-Body ] ;

Page 12: WebServer A Web server is a program that, using the client/server model and the World Wide Web's Hypertext Transfer Protocol (HTTP), serves the files that

Request line

The Request-Line begins with a method token, followed by the Request-URI and the protocol version, and ending with CRLF

GET / index.html HTTP /1.0 /r/n

General Header

There are a few header fields which have general applicability for both request and response messages General-Header = Date | Pragma

Page 13: WebServer A Web server is a program that, using the client/server model and the World Wide Web's Hypertext Transfer Protocol (HTTP), serves the files that

Request Header

Request-Header = Authorization | From ;

| If-Modified-Since ;

| Referer ;

| User-Agent

For ex:User-Agent: Mozilla/4.72 [en] (X11; I; OSF1 V5.1 alpha)

Page 14: WebServer A Web server is a program that, using the client/server model and the World Wide Web's Hypertext Transfer Protocol (HTTP), serves the files that

Entity Header Entity-Header = Allow ; | Content-Encoding ; | Content-Length ; | Content-Type ; | Expires ; | Last-Modified ; | extension-header

For exAccept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */* Accept-Encoding: gzip Accept-Language: en Accept-Charset: iso-8859-1,*,utf-8

Page 15: WebServer A Web server is a program that, using the client/server model and the World Wide Web's Hypertext Transfer Protocol (HTTP), serves the files that

Entity Body

The entity body (if any) sent with an HTTP request or response is in a format and encoding defined by the Entity-Header fields.

Entity-Body = *OCTET An entity body is included with a request message only when the

request method calls for one

Page 16: WebServer A Web server is a program that, using the client/server model and the World Wide Web's Hypertext Transfer Protocol (HTTP), serves the files that

Status-Line

The first line of a Full-Response message is the Status-Line, consisting of the protocol version followed by a numeric status code and its associated textual phrase

Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase /r/n

e.g., "HTTP/1.0 200 "

Page 17: WebServer A Web server is a program that, using the client/server model and the World Wide Web's Hypertext Transfer Protocol (HTTP), serves the files that

Response Line

The response header fields allow the server to pass additional information about the response which cannot be placed in the Status-Line. These header fields give information about the server and about further access to the resource identified by the Request-URI.

Ex

Location: http://www.w3.org/hypertext/WWW/NewLocation.html

Page 18: WebServer A Web server is a program that, using the client/server model and the World Wide Web's Hypertext Transfer Protocol (HTTP), serves the files that

Method Definitions

GET

The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI. If the Request-URI refers to a data-producing process, it is the produced data which shall be returned as the entity in the response and not the source text of the process, unless that text happens to be the output of the process.

Page 19: WebServer A Web server is a program that, using the client/server model and the World Wide Web's Hypertext Transfer Protocol (HTTP), serves the files that

HEAD

The HEAD method is identical to GET except that the server must not return any Entity-Body in the response. The metainformation contained in the HTTP headers in response to a HEAD request should be identical to the information sent in response to a GET request. This method can be used for obtaining metainformation about the resource identified by the Request-URI without transferring the Entity-Body itself. This method is often used for testing hypertext links for validity, accessibility, and recent modification

Page 20: WebServer A Web server is a program that, using the client/server model and the World Wide Web's Hypertext Transfer Protocol (HTTP), serves the files that

POST

The POST method is used to request that the destination server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI in the Request-Line. POST is designed to allow a uniform method to cover the following functions:

Annotation of existing resources; Posting a message to a bulletin board, newsgroup, mailing list, or similar group of articles;Providing a block of data, such as the result of submitting a form, to a data-handling process; Extending a database through an append operation.

Page 21: WebServer A Web server is a program that, using the client/server model and the World Wide Web's Hypertext Transfer Protocol (HTTP), serves the files that

How Does a Web Server Serve Content?

There is more to a Web server than its function as communications protocol. Ultimately, a Web server serves up content. This content must be identified in a way such that a Web browser can download and display that content in correctly. The primary mechanism for

deciding how to display content is the MIME type header. Multipurpose Internet Mail Extension (MIME) types tell a Web browser what sort of document is being sent. Such type

identification is not limited to simple graphics or HTML.

Page 22: WebServer A Web server is a program that, using the client/server model and the World Wide Web's Hypertext Transfer Protocol (HTTP), serves the files that

How Does a Web Server Accept Connections?

Web servers are designed around a certain set

of basic goals: Accept network connections from browsers. Retrieve content from disk. Run local CGI programs. Transmit data back to clients. Be as fast as possible

Page 23: WebServer A Web server is a program that, using the client/server model and the World Wide Web's Hypertext Transfer Protocol (HTTP), serves the files that

Project Discription

In this project, we wrote a basic web server  Java using the sockets API . The server can handle multiple request at a time. The browser servers as a client. The program takes as parameters a port number where the server will listen for incoming requests, and a local directory where the public html files reside.

Page 24: WebServer A Web server is a program that, using the client/server model and the World Wide Web's Hypertext Transfer Protocol (HTTP), serves the files that

Code Specification

The server is able to handle two different kinds of requests: the request of a file, and the request of a directory.

If the user requests a file and the file exists in  local directory, the file is sent back to the user. Otherwise an HTTP error is sent.

If the user requests a directory and the directory exists, an HTML document containing a listing of the directory contentsis sent. Each item is represented as a hyperlink. If the directory does not exist, again, an HTTP error is  sent.

The server  generates an access log, showing every successful

transaction. It should contain: the IP address of the client, the date and time of the request, and the name of the file or directory that was requested.