Skip to content Skip to navigation

OpenStax_CNX

You are here: Home » Content » how does a web browser get information from a web server

Navigation

Recently Viewed

This feature requires Javascript to be enabled.
 

how does a web browser get information from a web server

Module by: Pat Shuff. E-mail the author

Summary: The HTML standard has unified the way that web browsers get informaiton from a web server. In this section we will look at the interaction between the web browser and the web server and detail how a file is transferred from the web server to the client.

When a web browser talks to a web server, it uses something called a universal remote identifier (URI). The URI has multiple components but starts by telling the server the protocol that it wants to use. The protol that a web server supports is http . Other protocols that could be presented by a browser are ldap, ftp, and mailto. Unfortunately a web server does not know how to handle these protocols and would return an error. A complete list of valid URI values can be found in RFC 2717 and RFC 2718.

When a user enters a URI into the browser and presses the enter key, the web browser looks at the prefix before the colon and determines what protocol to use. It then looks at the text after the colon to figure out what server to communicate with. The http protocol specifies that the format for a request is http://server_name:port/directory/file The server_name can either be a computer name that gets resolved to an IP address or an IP address. The name resolution assumes that the client that you are running the web browser on knows how to translate names to IP addresses and also knows how to route the request to the computer answering for that IP address. We will not cover the name translation or IP routing in this section but focus on the communication assuming that these components work.

Let's look at an example. If a user enters http://myserver.myUniv.edu/test.txt then the browser will know that it is talking to a web browser by using the http as the protocol. It also knows that it is talking to myserver.myUniv.edu and is asking for the file test.txt. Since we did not define a port to use, the browser assumes that port 80 is the default port used to exchange data with the web server.

In our example, the web browser will open a socket from the local computer to the computer associated with the name myserver.myUniv.edu. The socket will request to connect to port 80 on the server and write the following data to the port is

  • GET /test.txt HTTP/1.1

The web server will then look for the file test.txt located in its http directory and read the contents from the file and write the contents to the socket opened by the client after it writes some HTTP protocol response information. An example of the protocol response is

  • HTTP/1.1 200 OK
  • Date: Thu, 30 Jun 2005 23:58:00 GMT
  • Server: Apache/2.0.54 (Unix) (Red-Hat/Linux)
  • Last-Modified: Wed, 08 Jun 2005 01:00:55 GMT
  • Accept-Ranges: bytes
  • Content-Length: 250
  • Connection: close
  • Content-Type: text/html

Since the web server was able to find the file, it returned an error code of 200 OK. This means that the file was found and its content follows. If the file was not available or could not be found, this error value would have been the only thing returned with a different error code. The return error codes are defined in the HTTP protocol specification.

The Date line is the date that the file was requested by the browser. The Server line tells the client browser what the server version is and potentially what the operating system is under the web server. This information can easily be suppressed in the configuration files for the web server. The Last-Modified line tells the browser the date that the file was last modified. The Content-Length line tells the browser how many bytes will follow the headers. The Connection line tells the browser to close the connection once the file is transferred. This can be configured to keep the connection open if more file information is to follow but typically the connection is closed and re-opened for each request. The Content-Type tells the browser the file type to expect and how to interpret the data to follow. In this example the data that follows on the socket will be text. The data could be raw text or html text. The browser will know how to interpret the file based on the extension. In our case the file name was test.txt so the data is treated as a raw stream of data and does not go through the html formatting engine of the browser. If the file were test.html, the data would be fed through the formatting engine and the html directives would cause the text to be displayed differently on the screen.

In summary, a web browser opens a connection to a web server based on the URI entered by the user. The URI specifies the protocol to use, typically http for web servers. It also specifies the server either by name or IP address and the port to use for the connection. The last entry in the URI includes the directory and file names that the browser is looking for. The web server takes the directory and file name and tries to find it in the file systems that it is using. The web server generates a HTTP response header and returns it to the web browser. If the file was not found or can not be accessed, the header is the only things that is returned contains the error codes. If the file can be found and can be accessed, the header and the file is returned.

Content actions

Download module as:

PDF | EPUB (?)

What is an EPUB file?

EPUB is an electronic book format that can be read on a variety of mobile devices.

Downloading to a reading device

For detailed instructions on how to download this content's EPUB to your specific device, click the "(?)" link.

| More downloads ...

Add module to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks