Response Header Lines of Static Files

This section provides a tutorial example on how to test and view HTTP response header lines returned by IIS on 3 types of static files: HTML document, GIF image file, and PDF document.

Since I am using Apache as the Web server, static files will be served directly by Apache server. It will set the status line and header lines for you based on the information collected from the static file the HTTP request is asking. For example, the "Content-Type" header line will be set based on the file name extension and the MIME settings of the server configuration. The "Content-Length" header line will be set to the size of the file.

Let's look at 3 examples of different types of static files. All of them are stored on my local machine at c:\inetpub\wwwroot, where the IIS is serving documents from.

1. Command: "php HttpRequestGet.php /hello.html" gives us:

HTTP/1.1 200 OK
Date: Sat, 26 Jan 2019 22:32:24 GMT
Server: Apache/2.4.37 (Win64)
Last-Modified: Sat, 18 Nov 2015 05:31:16 GMT
ETag: "26-405d03f0d1100"
Accept-Ranges: bytes
Content-Length: 38
Connection: close
Content-Type: text/html

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

Couple of interesting notes here:

2. Command: "php HttpRequestGet.php /dot.gif" gives us:

HTTP/1.1 200 OK
Date: Sat, 26 Jan 2019 22:36:08 GMT
Server: Apache/2.4.37 (Win64)
Last-Modified: Sat, 26 Jan 2019 22:35:47 GMT
ETag: "2b-5806410a1577b"
Accept-Ranges: bytes
Content-Length: 43
Connection: close
Content-Type: image/gif

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 include the entire entity body here because it contains binary data.

3. Command: "php HttpRequestGet.php /hello.pdf" gives us:

HTTP/1.1 200 OK
Date: Sat, 26 Jan 2019 22:38:19 GMT
Server: Apache/2.4.37 (Win64)
Last-Modified: Sun, 27 Jul 2003 21:22:12 GMT
ETag: "38d-3c37707f2a900"
Accept-Ranges: bytes
Content-Length: 909
Connection: close
Content-Type: application/pdf

%PDF-1.3
% ...
4 0 obj
......

Again, Content-Type was set correctly to "application/pdf" for file name extension "pdf", as defined in the MIME settings. I truncated the entity body to save some space.

Last update: 2019.

Table of Contents

 About This Book

 Introduction and Installation of PHP 7.3

 PHP Script File Syntax

 PHP Data Types and Data Literals

 Variables, References, and Constants

 Expressions, Operations and Type Conversions

 Conditional Statements - "if" and "switch"

 Loop Statements - "while", "for", and "do ... while"

 Function Declaration, Arguments, and Return Values

 Arrays - Ordered Maps

 Introduction of Class and Object

 Integrating PHP with Apache Web Server

 Retrieving Information from HTTP Requests

 Creating and Managing Sessions in PHP Scripts

 Sending and Receiving Cookies in PHP Scripts

Controlling HTTP Response Header Lines in PHP Scripts

 What Is an HTTP Response

 HTTP Response Header Lines

 header() - Inserting a Raw Header Lines

 HttpRequestGet.php - Viewing Header Lines

Response Header Lines of Static Files

 HttpHeaderLines.php - Examples of Inserting Header Lines

 Location: - Forcing the Browser to Redirect to Another URL

 Content-Type: - Generating Non-HTML Response Body

 Content-Disposition: - Sending Files for Downloading

 MySQL Server Connection and Access Functions

 Functions to Manage Directories, Files and Images

 SOAP Extension Function and Calling Web Services

 SOAP Server Functions and Examples

 Localization Overview of Web Applications

 Using Non-ASCII Characters in HTML Documents

 Using Non-ASCII Characters as PHP Script String Literals

 Receiving Non-ASCII Characters from Input Forms

 "mbstring" Extension and Non-ASCII Encoding Management

 Managing Non-ASCII Character Strings with MySQL Servers

 Configuring and Sending out Emails

 Outdated Tutorials

 References

 Full Version in PDF/EPUB