ASP Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 4.11

Controlling HTTP Response Header Lines

Part:   1  2  3  4 

ASP Tutorials - Herong's Tutorial Notes © Dr. Herong Yang

hyBook - Guestbook Application

Using MS Access Databases

ActiveX Data Object (ADO)

Controlling Response Header Lines

Microsoft Scripting Runtime DLL

Using Cookies

ASP Sessions

ASP Objects

Microsoft Script Debugger

Internet Information Services (IIS)

... Table of Contents

(Continued from previous part...)

Viewing Response Header Lines

When the client program receives the HTTP response, it will look at the header lines first. Based on the information contained in the header lines, the client program will decide what to do with the actual response data in the entity body.

If you use a Web browser as a HTTP client program, it will process the data in the entity body differently depending on mainly the "Content-Type" entity header line: displaying the data as it is, rendering the data as a HTML document and displaying the resulting information, or passing the data to other registered programs to handle it.

Once the Web browser finishes processing the entity body, you can get some limited information from the header lines. For example, you can click the right mouse button and select the properties command on Internet Explorer, it will display some general properties about this response in a pop up window. The properties displayed are not always identical to the response header lines. The "Modified" property is probably identical to the "Last-Modified" entity header line. The "Type" property is sometime related to the "Content-Type" entity header line, and sometimes related to server side resource that generated the response.

How to view all the header lines received in the HTTP response? I couldn't find any existing tools to do this. So wrote the following program to dump the entire response including all header lines received from a Web server:

/**
 * HttpRequestGet.java
 * Copyright (c) 2002 by Dr. Herong Yang. All rights reserved.
 */
import java.io.*;
import java.net.*;
public class HttpRequestGet {
   public static void main(String[] args) {
      String path = "/index.html";
      int port = 80;
      String host = "localhost";
      if (args.length > 0) path = args[0];
      if (args.length > 1) port
         = Integer.valueOf(args[1]).intValue();
      if (args.length > 2) host = args[2];
      String result = "";
      try {
         Socket c = new Socket(host,port);
         BufferedWriter w = new BufferedWriter(new OutputStreamWriter(
            c.getOutputStream()));
         BufferedReader r = new BufferedReader(new InputStreamReader(
            c.getInputStream()));
         String m = "GET "+ path + " HTTP/1.0";
         w.write(m,0,m.length());
         w.newLine();
         w.newLine();
         w.flush();
         while ((m=r.readLine())!= null) {
            System.out.println(m);
         }
         w.close();
         r.close();
         c.close();
      } catch (IOException e) {
         System.err.println(e.toString());
      }
   }
}

Response Header Lines of Static Files

Static files can be served directly by IIS server, if you copy files to \inetpub\wwwroot, IIS will set "Content-Type" header line based on the file name extension and the MIME settings of the server configuration. Let's look at 3 commonly used file name extensions.

1. Command: "java HttpRequestGet /hello.html 80" gives us:

HTTP/1.1 200 OK
Server: Microsoft-IIS/5.0
Date: Sat, 28 Dec 2002 19:27:28 GMT
Content-Type: text/html
Accept-Ranges: bytes
Last-Modified: Sat, 28 Dec 2002 15:05:54 GMT
ETag: "0f597e0a8e8c21:903"
Content-Length: 38

<html><body>Hello world!</body></html>

Couple of interesting notes here:

  • Content-Type was set to "text/html", because the file name extension was "html".
  • The request was marked as HTTP/1.0 in HttpRequestGet, but IIS responded with a higher version, HTTP/1.1.

2. Command: "java HttpRequestGet /dot.gif 80" gives us:

HTTP/1.1 200 OK
Server: Microsoft-IIS/5.0
Date: Sat, 28 Dec 2002 03:14:22 GMT
Content-Type: image/gif
Accept-Ranges: bytes
Last-Modified: Sun, 11 Aug 2002 21:48:20 GMT
ETag: "0aafb4ddc43c21:903"
Content-Length: 43

GIF89a......

As you can see, Content-Type was set correctly to "image/gif" for file name extension "gif", as defined in the MIME settings. I could not included the entity body here because it contains binary data.

(Continued on next part...)

Part:   1  2  3  4 

Dr. Herong Yang, updated in 2002
ASP Tutorials - Herong's Tutorial Notes - Controlling HTTP Response Header Lines