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

HTTP Response Syntax

Based on HTTP/1.1 protocol, after receiving and interpreting an HTTP request from a client, a server must responds with an HTTP response following the syntax bellow:

status-line
header-line
...
header-line

entity-body

Note that:

  • Response must have one status-line.
  • Response can have zero, one, or many header lines.
  • Response can only have zero or one entity-body.
  • There is a blank line between header lines and the entity body.
  • Status line, head line, and blank line must be ended with CRLF ("/r/n") characters.
  • Entity body is the actual data requested by the client request.
  • Header lines can be in any order.

Bellow is a simple HTTP response with two header lines:

HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 38

Hello world!

HTTP Response Header Lines

HTTP/1.1 response header lines allows the server to passes additional information about the response which cannot be placed in the status line. Header lines can be divided into three groups:

1. General header lines: Information about the transmission of the entire response message:

   Cache-Control      
   Connection         
   Date               
   Pragma             
   Trailer            
   Transfer-Encoding  
   Upgrade            
   Via                
   Warning          

2. Response header lines: Information about the response:

   Accept-Ranges     
   Age               
   ETag              
   Location          
   Proxy-Authenticate
   Retry-After       
   Server            
   Vary              
   WWW-Authenticate

3. Entity header lines: Information about the data requested by the client:

   Allow              
   Content-Encoding   
   Content-Language   
   Content-Length     
   Content-Location   
   Content-MD5        
   Content-Range      
   Content-Type       
   Expires            
   Last-Modified      

Controlling Response Header Lines

When an ASP page is requested, the response header lines will be created by the ASP server. But you can indirectly control some header lines in three 2 different ways:

1. Modifying two special properties of the "response" object to set the entity header line: Content-Type as shown in the following example:

   response.ContentType = "text/plain"
   response.Charset = "ISO-8859-1"

These two statements will generate the the following header line:

Content-Type: text/html; Charset=ISO-8859-1

2. Using the generic method on the "response" object to add any response header lines as shown in the following example:

   response.AddHeader "Author", "Herong Yang"

There seems to be no SetHeader method on the reponse to let you reset the default header lines generated by the ASP server. You can only add new header lines.

(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