[ Previous ] [ Contents ] [ Index ] [ Next ]

Example 2: showhdrs

The following example script shows how to access the HTTP headers sent by the client within a Tcl script.

This example can be found in the examples/tcl/showhdrs.tcl file.

    
    # Example 2: Show header data
    # 
    # Things to notice:
    #
    # * The same function is registered for two different URLs
    #   with different context.
    #
    # * The headers are pulled out of the conn using the
    #   ns_conn function.
    #
    # * The value for a particular header line is extracted 
    #   with "ns_set iget", the case insensitive counterpart to
    #   "ns_set get".
    
    ns_register_proc GET /example/showbrowser showheader USER-AGENT
    ns_register_proc GET /example/showrefer showheader REFERER
    
    proc showheader {conn key} {
        set value [ns_set iget [ns_conn headers $conn] $key]
      ns_return $conn 200 text/plain "$key: $value"
    }
    
    
    

Top of Page

[ Previous ] [ Contents ] [ Index ] [ Next ]
Copyright © 1996 America Online, Inc.