Gethdrs

gethdrs is a program that displays HTTP headers, and optionally content provided the content is textual. It is useful primarily for debugging or testing, and handles both direct requests and HTTP redirects. When HTTP redirects are used by a web server, gethdrs will show headers for each redirect individually. gethdrs can use proxies for HTTP, HTTPS. Proxies can be turned on and off as desired, to facilitate comparing HTTP responses with and without a proxy.

gethdrs can be run using a GUI or as a command-line program. The GUI is generally more convenient.

Running Gethdrs with a GUI

To start the GUI, one simply runs gethdrs with no arguments. The application will display a window with a series of text fields, check boxes, and buttons near the top of the screen, just above a large text area which will display the output. In addition to menus, gethdrs provides support keyboard navigation.

The initial view displayed shows the data needed to formulate an HTTP request. For the simplest use, one can simply enter a URL into the text box and type RETURN. Otherwise one can use the TAB key to move forwards or SHIFT-TAB to move backwards to cycle through buttons and text fields. When at a button or checkbox, the SPACE key selects it (this is the normal Java convention for Java's default look and feel.) Output will appear in the Output view (see the View menu.) After typing RETURN in the Request Data view, the GUI will automatically shift to the Output view. If you cancel a request, however, one will switch back to the view that existed when the request was started.

gethdrs is controlled by the following controls in all views:

Output View

Once a request has been sent, the Output view will be displayed (you can send simple requests from this view, but to change other parameters (i.e, for POST or PUT methods), you must first use the Request Data view. For the Output view, the Page-Up and Page-Down keys will scroll the content window up and down by a full page. These keys cause text to scroll the start and end of respectively if pushed when the control key is down. The Home and End keys will move the cursor to the start and end of the URL text field when this field has the keyboard focus, and for convenience, this is usually the case. To move to the start and end of the output, use Control-PageUp and Control-PageDown respectively.

Request Data View

The Request Data view can be traversed using keyboard navigation. While the platform defaults are used, typically a TAB key will traverse in one direction, SHIFT-TAB in the reserve direction, and SPACE will select the current button. There are two exceptions. In the header table and input text frame (the last frame in the view), you need to use CONTROL-TAB and CONTROL-SHIFT-TAB. Otherwise you will either stay in that particular view or will enter a character. The controls are as follows (many contain a button to provide dialog boxes, followed by a text box containing the value, and either may be used as desired):

There are several controls:

The headers and values that will be used will appear in a header table and text area (separated by a movable bar.) These are controlled by five buttons:

While normally one will simply read in data from a file, the user may also choose to edit the text or header values. The edited values will be used when possible. For binary data or any text format not recognized by gethdrs, an indication of the file name will appear in the text box, and cannot be meaningfully edited. In most cases there will be no attempt at verifying that the data provided has the format specified by the corresponding media type - as am example, for testing web severs it can be useful to be able to send incorrectly formatted data.

Preferences View

Preferences can be displayed and modified by selecting the Preferences item in the View menu, which will show a series of check boxes and text fields. The check boxes enable various proxies (HTTP, HTTPS, FTP, and SOCKS.) An additional checkbox sets the default value for the "use proxy" checkbox (the value used when gethdrs is started) in the top portion of the frame. A final checkbox allows the user-agent header to be changed from the default (e.g., to mimic a specific browser for cases where a web page may provide different content for one browser than another.)

For each proxy that is going to be used, the proxy text fields should give a host (or internet address in "dot" notation) and a port number. The "Exclude from Proxy" text fields may contain a hosts for which the proxy should not be used, with each host separated from the others by a vertical bar "|". Each host name can contain a "*", which serves as a wildcard.

The "Save Preferences" button should be clicked to save a change in preferences so that these values will be loaded when gethdrs is restarted. The "Cancel Changes" button causes preferences to revert the last saved values or the initial value when gethdrs was started. Regardless of whether the current preferences have been saved, the values displayed will be in effect whenever the application gets HTTP headers from a web site. The Export Prefs menu option will store the current preferences in a file so these can be used with the -P option (when used with a GUI, this options suppresses the preferences panel).

Menus

The gethdrs application has 4 menus.

Running from a Terminal

When started with no arguments, the GUI is displayed. Otherwise the syntax is

gethdrs [-p ] [-P PROPFILE ] \
     [-u] [-m get|head|post|put] [-n N|all] \
     [-c CHARSET] [-t MEDIATYPE] \
     [-h HEADERFILE] [-i INPUTFILE] URL
gethdrs -h

The URL argument must be a URL for a supported protocol. Most of the options (there are two exceptions) take a mandatory argument. This argument must be a single token as seen by a shell, and will in some cases have to be quoted (the main case is the -t option, as a media type may include characters interpreted by a shell.) The options are as follows:

When run with command-line arguments, output appears on standard output. The main use of the command-line options is for use of the program in a script.

Exported Preference Syntax

An exported preference file is a Java property file that contains lines with keyword-value pairs, separated by either a colon or an equal sign. blank lines and lines starting with "#" or "!" are ignored. Long lines may be continued by placing a backslash "\" at the end. The following properties are recognized:

These are the same system properties as those defined in the Java class libraries for networking. Additional java options can be used as well and particularly useful ones are:

For example, the following program implements a trivial web server using HTTPS, coded using the libbzdev-java package:


     import org.bzdev.ejws.*;
     import org.bzdev.ejws.maps.*;

     public class STest {
         public static void main(String argv[]) throws Exception {
            EmbeddedWebServer ews =
              new EmbeddedWebServer(8080, 48, 10,
                                    new
                                    EmbeddedWebServer.SSLSetup());
            ews.add("/", DirWebMap.class, new File("./", null, 
                    true, true, true);
            ews.start();
         }
     }

The corresponding gethdrs property files (assume it is named PropFile) is


    javax.net.ssl.trustStore = /usr/share/bzdev/ejwsCerts.jks
    javax.net.ssl.trustStorePassword = changeit
which can be used with the command

     % gethdrs -P PropFile
Then gethdrs will have the certificate needed to connect to the server at <https://localhost:8080/>.