HTTPD

Synopsis

HTTPD [/?] [/ACCESSLEVEL number] [/VIRTUAL[+|-]] [/INDEX string]] [/DEFMIMETYPE string] socket

Description

HTTPD provides HTTP content (a.k.a. "origin") service, accepting HTTP queries on its input and sending HTTP responses on its output. If no socket is specified as an argument, it uses its standard input and standard output for input and output. Otherwise, it uses the named socket, which it closes when it has finished with it. The IP address and TCP port number on which content HTTP service is thus provided is determined by its parent process, not HTTPD itself. Conventionally, the port number is 80 and the IP address is one that is reachable by Internet at large.

HTTPD is designed to be spawned on demand by TCPSRUN. It can also be spawned by INETD, although the control of client access levels based upon the client's IP address, which TCPSRUN does, will be unavailable as a consequence.

Where client access is denied, HTTPD simply exits immediately, closing the socket. With any other access level, normal HTTP service is provided.

HTTPD accepts GET and HEAD requests. In response to any other request it issues an error response and terminates. The GET and HEAD requests may be in HTTP/1.0 or HTTP/1.1 format.

HTTPD supports virtual hosting. Requests may omit the hostname from the URL in the request. In which case, the hostname is taken from a Host: header, if one is supplied. HTTP/1.0 requests are allowed to omit the Host: header as well, in which case the hostname is the default hostname "0". (HTTP/1.1 requests without hostnames cause an error response.) If the /VIRTUAL option is enabled, a request for http://host/path refers to the file or directory ./host/path relative to HTTPD's working directory. If the /VIRTUAL option is disabled, a request for http://host/path refers to the file or directory ./0/path relative to HTTPD's working directory.

In order to prevent the malicious from having access to arbitrary files and directories, HTTPD pre-processes the pathname, replacing any ".." pathname components with "//". (Proper processing of ".." in hyperlinks is supposed to be done by HTTP clients.)

If the pathname ends in a trailing slash, HTTPD first appends the default index filename to it. If the pathname indicates a directory, HTTPD responds with a client-side redirect message appending a trailing slash to the URL. If the pathname indicates a file, HTTPD serves up the file.

HTTP constructs the MIME content type for files from information in extended attributes, if available. Failing that, it determins the extension of the filename name, .ext, and looks for an environment variable CONTENTTYPE_EXT_ext named after that extension, and if the variable exists uses its value as the MIME content type. Failing that, it falls back to the default MIME content type specified.

HTTPD writes log information to its standard error, listing each request that is processed.

Example RUN file

A "TCPService.RUN" run file, for HTTPD to be spawned by TCPSRUN, would typically look similar to:

  program %APPS%\JdeBP\IU\Bin\HTTPD.exe
  argument HTTPD
  argument %3

TCPSRUN itself would be invoked under RUNSVC, the Service Manager in the OS/2 Command Line Utilities version 2.2, with a run file similar to:

  program %APPS%\JdeBP\IU\bin\TCPSRun.exe
  chdir %_BOOT%:\Config\Services\%1
  argument TCPSRun
  argument 0.0.0.0
  argument www-http
  argument TCPService.RUN

Command-specific options

/VIRTUAL
Enable or disable virtual host support. By default this is enabled.
/INDEX
Specify the name of the default file suffix for directory URLs. The default is index.html.
/DEFMIMETYPE
Specify the name of the default mime type, if none can be determined. The default is text/html.

The Internet Utilities are © Copyright Jonathan de Boyne Pollard. "Moral" rights are asserted.