NaviServer - programmable web server

[ Main Table Of Contents | Table Of Contents | Keyword Index ]

# ns_conn(n) 4.99.8 naviserver "NaviServer Built-in Commands"

## Name

ns_conn - Find information about the current HTTP connection

## Table Of Contents

## Synopsis

- ns_conn option ?arg arg ...?
- ns_conn auth
- ns_conn authpassword
- ns_conn authuser
- ns_conn channel
- ns_conn clientdata ?value?
- ns_conn close
- ns_conn compress ?level?
- ns_conn content ?-binary? ?offset? ?length?
- ns_conn contentfile
- ns_conn contentlength
- ns_conn contentsentlength ?bytes?
- ns_conn copy off len chan
- ns_conn driver
- ns_conn encoding ?encoding?
- ns_conn fileheaders file
- ns_conn filelength file
- ns_conn fileoffset file
- ns_conn files
- ns_conn flags
- ns_conn form
- ns_conn headers
- ns_conn host
- ns_conn id
- ns_conn isconnected
- ns_conn keepalive ?value?
- ns_conn location
- ns_conn method
- ns_conn outputheaders
- ns_conn peeraddr
- ns_conn peerport
- ns_conn pool
- ns_conn port
- ns_conn protocol
- ns_conn query
- ns_conn request
- ns_conn server
- ns_conn sock
- ns_conn start
- ns_conn status ?value?
- ns_conn timeout
- ns_conn url
- ns_conn urlc
- ns_conn urlencoding ?encoding?
- ns_conn urlv
- ns_conn version
- ns_conn zipaccepted

## Description

This command is used to retrieve various pieces of information about a connection.

## COMMANDS

ns_conn option ?arg arg ...?

The subcommands of ns_conn are (in alphabetical order):

ns_conn auth

  Returns all authorization headers as a ns_set. For Basic authentication there are reserved keys: Username and Password, these are the keys returned by ns_conn authuser and ns_conn authpassword. This ns_set can be updated.

ns_conn authpassword

  Returns the decoded user password from the authorization data.

ns_conn authuser

  Returns the decoded user name from the authorization data.

ns_conn channel

  Returns the Tcl channel name for the current connection.

ns_conn clientdata ?value?

  Query or set the client date of the current connection. The client data is provided by the application and is potentially passed to different threads and can be used to establish the context with the connection thread. For example, the writer thread outputs the client data when listing running connections (one can determine e.g. which user has initiated the delivery, etc.).

ns_conn close

  Closes the connection so the script (or ADP) can do any time-consuming processing without making the client wait. If you use ns_conn close in an ADP, streaming should be turned on before closing the connection (i.e. <SCRIPT RUNAT=SERVER STREAM=ON>) or nothing will get sent out at all.

ns_conn compress ?level?

  Either set or query the compression level for the current connection. Use ns_conn compress 0 to indicate that compression should be deactivated

ns_conn content ?-binary? ?offset? ?length?

  Returns the content of the HTTP request body, optionally a substring of that content starting at offset and extending length characters. If the option -binary is used, the content is returned raw. Otherwise, a conversion to the encoding of the connection is performed. Note that the client response might be returned as string content (as retrieved by this command) or as file (see ns_conn contentfile ).

ns_conn contentfile

  Returns name of the temporary file which holds contents of the request. Whether of not a content files is returned depends on the configuration settings.

ns_conn contentlength

  Returns the number of bytes in the content passed in.

ns_conn contentsentlength ?bytes?

  Returns or sets the number of bytes in the content to be sent.

ns_conn copy off len chan

  Copies data from the current connection to chan starting at byte off for len bytes.

ns_conn driver

  Returns the name of the module (nssock or nsssl) that is acting as the communications driver for this connection.

ns_conn encoding ?encoding?

  Query or set the encoding for the current connection.

ns_conn fileheaders file

  Return the header information for the uploaded file with the specified name (returned via [ns_conn files]).

ns_conn filelength file

  Return the length of the uploaded file with the specified name (returned via [ns_conn files]).

ns_conn fileoffset file

  Return the offset of the uploaded file with the specified name (returned via [ns_conn files]).

ns_conn files

  Return files uploaded with the current form.

ns_conn flags

  Return the internal flags of the current connection. Use with care, the flags might change over versions.

ns_conn form

  Returns any submitted form data as an ns_set. This form data may have been submitted with a POST or appended to the URL in a GET request. Note: ns_conn form is not suitable for multipart formdata file upload widgets.

ns_conn headers

  Returns all the header data as an ns_set. The keys of the ns_set represent the field names. The case of the returned field names depends on the HeaderCase configuration parameter. By default, HeaderCase is "Preserve", which means case is preserved.

ns_conn host

  Returns the host part of the URL in the HTTP request line. This is only set, when the NaviServer is used as a proxy server.

ns_conn id

  Returns the unique identifier of the current connection.

ns_conn isconnected

  Returns 1 if you're in a connection thread, and you are therefore allowed to make calls to ns_conn. It returns 0 if you're not in a connection thread (such as when you're in a schedule procedure) and you are not allowed to make calls to ns_conn.

ns_conn keepalive ?value?

  Query or set the keepalive for the current connection.

ns_conn location

  Returns the location string for this virtual server in the form: protocol://hostname[:port].

ns_conn method

  Returns the HTTP method, e.g. GET.

ns_conn outputheaders

  Returns an ns_set containing the headers that will be sent out when a result is returned to the client. This ns_set can be manipulated like any other ns_set. You can also use this command to write to the set of output headers. For example: ns_set put [ns_conn outputheaders] key value.

ns_conn peeraddr

  Returns the IP address of the client, i.e. the "other side" of the HTTP connection. The IP address is returned in the form of a string separated with periods (e.g., 155.164.59.75).

ns_conn peerport

  Returns the port of the client, i.e. the "other side" of the HTTP connection.

ns_conn pool

  Returns the current connection pool from the currently connected server.

ns_conn port

  Returns the port specified explicitly in the URL of the HTTP request. If the browser does not explicitly send the ":port" part of the URL, the port number returned will be 0.

ns_conn protocol

  Returns the protocol of the URL in the HTTP request line. This is only set, when the NaviServer is used as a proxy server.

ns_conn query

  Returns any query data that was part of the HTTP request.

ns_conn request

  Returns the HTTP request line as presented by the client, e.g. GET / HTTP/1.1.

ns_conn server

  Returns the name of the server handling the request.

ns_conn sock

  Returns the socket id (integer fd) of current connection.

ns_conn start

  Returns the time the connection request started in "sec:usec" (aka ns_time) format.

ns_conn status ?value?

  Query or set the HTTP status code for the current connection.

ns_conn timeout

  Returns absolute time value beyond which conn should not wait on resources, such as condition variables.

ns_conn url

  Returns the URL of the HTTP request. This is the portion of the request after the hostname, for example [ns_conn url] on returns /index.adp.

ns_conn urlc

  Returns the number of elements (delimited by `/') in the URL of the HTTP request.

ns_conn urlencoding ?encoding?

  Query or set the url encoding for the current connection.

ns_conn urlv

  Returns a list containing the pieces of the URL delimited by `/'.

ns_conn version

  Returns the version of the HTTP request. This is usually 1.0 or 1.1.

ns_conn zipaccepted

  Returns 0 or 1 depending on whether or not the client accepts a zip encoded response.

## EXAMPLES

    if { [string match /page/* [ns_conn url]] } {
      ns_returnnotfound
    }

## See Also

ns_adp, ns_getform, ns_queryget, ns_time

## Keywords

connection, gzip