File: links-configure-extns.html, Node: File Extensions, Content-Types ..., Next: Other Configuration Options, Prev: Colour, Up: Configuring Links

# 2.4 File Extensions, Content-Types and Associations

# [Version 0.82]

This section describes how Links handles content-types, and the appropriate use of file extensions and associations.

For a quick and simple solution, see the the examples in the sections "Passing Files to External Applications" [3.3] and "Installing and Configuring WWW Plug-ins" [3.2].

### Page Contents

- 2.4.1 General Definitions
- 2.4.2 Links and content-type handling
- 2.4.3 Setting up file extensions
- 2.4.4 Setting up associations
- 2.4.5 Associations and flags

### 2.4.1 General Definitions

These general definitions will help in understanding the explanations and reasoning of the following sections.

#### File Extensions

A suffix preceded by a dot separator appended to a filename, which can be used to identify the format of the file.

Examples are:

.html and .html ... HyperText Markup Language format

.ps ... PostScript document text

.jpg ... JPEG image data

.png ... PNG image data

#### Content-Types

A definition of a format type derived from a file extension code.

Examples are:

HyperText Markup Language ... text/html

PostScript text ... application/postscript

JPEG image data ... image/jpeg

PNG image data ... image/png

#### Associations

A formatted entry in a database or file which is readable by some browsing programme (like Links), which associates a local application with a content-type.

Examples for Links (in the Links.cfg file), could include:

association "Images Console" "image/jpeg" "zgv %" 5 1

association "Postscript Documents" "application/postscript" "gv %" 2 1

These examples associate the content-type image/jpeg with the programme "zgv", and the content-type application/postscript with the programme "gv".

### 2.4.2 Links and content-type handling

At a general level, each file request Links makes with a http://, ftp://, or file:// request should at some stage pass through a process that provides a content-type definition for the requested file.

#### HTTP requests

For HTTP, content-type definition occurs on the server side, so Links parses the HTTP header (returned prepended to the requested file) and uses that content-type value for the current file.

Example: A HTTP Header (with content-type marked)
            HTTP/1.1 200 OK
            Date: Tue, 22 Feb 2000 15:38:24 GMT
            Server: Apache/1.3.0 (Unix) Debian/GNU
            Last-Modified: Mon, 17 Jan 2000 13:18:05 GMT
            ETag: "2d5a1-d6b-3883168d"
            Accept-Ranges: bytes
            Content-Length: 3435
            Connection: close
       -->  Content-Type: text/html <--

#### FTP and local file requests

For FTP and local file requests two processes take place to find definitions for content-types:

1. Links checks the filename for either of the suffixes .htm and .html. If the filename contains one of these extensions, the content-type is defined as "text/html".

2. Links will check the list of extension entries from the Links.cfg file, and will accept any valid content-type definitions.

If Links does not find any content-type definition for the current requested file, the file will be "displayed" as plain text, even if it a image or other kind of binary file.

It therefore makes sense to set up file extensions for any content-types you regularly invoke through Links while browsing your file systems.

Example: File Extension entry in Links.cfg
            extension "ps,ai,eps" "application/postscript"

The above example will define for any FTP or local file requests, that filenames ending with .ps, .ai, or .eps belong to content-type "application/postscript".

#### Summary

When making an HTTP request to a web server, the web server provides the content-type definition for Links in the HTTP header. When making a FTP or local file request, Links needs a local set of definitions to have been set up in the form of extension entries in the Links.cfg for any extensions except .html and .htm.

#### HTTP requests and associations

1. The final part of content-handling is a "destination application", i.e. an association entry in the Links.cfg file.

2. In cases of the text/html content-type, Links handles the rendering and display of this type by itself. For any other text types requested by HTTP, Links will render and display the file.

3. For all other content-type requests, an external application ("association") is required.

#### FTP and local file requests, and associations

1. For the text/html content-type, Links will render and display the file, as expected. (You will have to set up an extension entry for HTML files not ending in .htm or .html, or rename those files to end in the latter.)

2. For other text files requested from FTP or local files, you can alter the behaviour of Links by setting up a content-type and an association, so for example, you can get a pager programme to handle the display and rendering of non-html text types.

3. If any other content-types have been defined with an extension entry, you can associate a programme with that content-type. This works for HTTP requests as well, so you only have to do it once.

### 2.4.3 Setting up file extensions

As the above discussion demonstrated, file extensions are used to deliver content-type definitions to Links for files returned from FTP and local file requests.

While it is advisable to stick to the formal definitions given by MIME type specifications, it is not a compulsory requirement. You can quite easily invent your own content-types for your own usage (see the example in [3.3.3]).

When adding one or two content-type definitions to Links, the menu system provides a convenient and easy method.

1. Go to Menu --> Setup --> File extensions --> Add, (or press <ESC>-s-e-a).

2. Enter the "extension(s)" for one content type.
Note: In cases where there is more than one file extension for a single content type, you can enter a comma separated list of file extensions, like
extn1,extn2,extn3

3. Enter the content-type, in the form

image/blobby.

4. Confirm the creation of the entry by pressing return or clicking on "[OK]".

5. If you want to set up an association, follow the next sections' instructions. If not, save the changes now by pressing <ESC>-s-s ("Save options").

Alternatively, you can directly edit your Links.cfg file, where extensions take the following form, including the quote marks:

               extension "img" "image/image"
               ^^^^^^^^^  ^^^   ^^^^^^^^^^^
                 (1)      (2)      (3)

These, respectively, represent:

- 1) declaration of Links variable type,
- 2) file extension (without leading dot separator),
- 3) content-type (as defined by mime types).

There is a file in the appendix of this manual which might prove to be useful for the purpose of editing the Links.cfg file.

"101 Extensions and MIME-types" [A.2] contains more than 100 extensions and their content-types in a Links-compatible format. Just cut and paste or grep(1) the entries without the commented lines to your Links.cfg file.

When you are finished, save the changes to the file and restart Links.

### 2.4.4 Setting up associations

Association entries in Links establish a relationship between a content-type and an application external to Links; for example, an image viewer. Included in each entry is a command entry which is used to invoke a programme.

For associations which will be used for HTTP requests, you need to stick to the formal definitions of content-types given in generally used MIME type lists, otherwise they will not work. For local and FTP file requests, you have a little more freedom because you can define your own content-types by using file extensions.

An important exception in Links, is that is cannot deal with compound file suffixes as is commonly found with gzipped file extensions (e.g. filename.tar.gz). The reason is that when Links generates the tempfile name, it only preserves the characters including and after the last dot separator.

For example, the filename "postscript-gzipped.ps.gz" will be converted to something like links01322aaa.gz, so although it is easy to identify that this is a gzipped file, the "I am a postscript file" information is stripped away.

To set up an association between one or more content-types and an application using the menu system,

1. Go to Menu --> Setup --> Association --> Add, (or press <ESC>-s-a-a.

2. Enter a generic label description like

Image Display in X-Windows.

3. Enter the content-type(s) to be handled by the associated programme. More than one content-type can be listed separated by commas in the form

image/blobby,image/wobbly,image/blurred

4. Enter the associated application name with any command options, in the form

<path to binary>blobviewer -quiet %

where "%" is expanded to the /tmp filename that Links generates.

5. Choose a combination of the checkboxes:

[X] Run on terminal [X] Run in X-Window [X] Ask before opening

to control how Links will behave in relation to the associated application. (See the table below, [2.4.5] for Links' behaviour with every possible combination.)

6. Press [OK] to confirm.

7. Save the changes now by pressing <ESC>-s-s ("Save options").

You can also directly edit your Links.cfg file to produce an association entry, which are written in the following form.

                 association "Images Console" "image/image,image/blobby" "progname -option1 -option2 %" num num
                 ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^
                      (1)          (2)                   (3)                           (4)                (5)

These, respectively, represent:

- (1) declaration of Links variable type,
- (2) an arbitrary label describing a group of content-types,
- (3) content types to be handled by progname,
- (4) application name and path with any standard command line options and the Links filename expansion character "%",
- (5) num num are flags which control how Links will behave when a file is passed to an external application. (See the table below, [2.4.5].)

When you are finished, save the changes to the file and restart Links.

Prior to setting up an "association" entry, it is probably wise to test how your command really works.

Take the whole of the command (marked as (4), above) and replace the Links expansion character with a real filename of the appropriate content type, and run it from a command line prompt. Do note that if an application runs in the terminal window that you invoke it from, Links will be pushed into the background when the application is invoked as a Links association.

### 2.4.5 Associations and flags

Links permits some measure of control over its behaviour when handling the invocation of associated applications, by using flags.

The flags for association entries show up in the menu system (Setup--> Association --> Add) as a combination of three checked / unchecked boxes, while in the Links.cfg file, you will find the flags as two digits at the end of each entry, for example:

          association "jpg" "image/jpeg" "xv %" 2 1
                                                ^^^

This table shows all eight legal flags and checkbox combinations (2^3) and the associated behaviour. (Note: the second digit of the flag entry refers to the operating system: 1 = Unix, 2 = OS/2, 3 = MS Win32.)

Links.cfg | Menu system | Events
--- | --- | ---
Flag Entry | Term | X-Term | Ask?
0 1 |  |  |  | Acts as if Association entry does not exist at all, standard "unknown type" dialog pops up with options to Save, Display (in text mode), or Cancel.
1 1 | X |  |  | Links is pushed to the background and prog executes in the current Term window. Links returns to the foreground when prog exits. If prog requires it's own X-window, standard "unknown type" dialog pops up. Use for: Console programmes.
2 1 |  | X |  | If prog runs in it's own (or assigned) X-window, prog will execute. If prog requires an x-term to execute (e.g xterm -e prog) and none is given, invocation will fail and the standard "unknown type" dialog pops up. Use for: X programmes.
3 1 | X | X |  | Links is pushed to background while current instance of prog executes and completes. When prog exits, Links returns as a foreground process. Use for: Console and X programmes.
4 1 |  |  | X | Ask; and same as [0 1], above.
5 1 | X |  | X | Ask; and same as [1 1] above.
6 1 |  | X | X | Ask; and same as [2 1] above.
7 1 | X | X | X | Ask; and and same as [3 1] above.

User Reference Manual for Links Version 0.82 | Revision Date: 2000-02-23

Copyright (C) 2000 Cliff Cunnington, <cliff@ccnet.demon.nl>

Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.