---
name: "Ns_ConnCondSetHeaders"
section: "3aolserver"
platform: "linux"
package: "aolserver4-dev"
version: "4.5.1-18.1"
release: "Debian 9 (Stretch)"
platforms: ["linux"]
url: "https://new.carta.tech/Ns_ConnCondSetHeaders/3aolserver"
---

# Ns\_ConnCondSetHeaders(3aolserver)

Routines to manage response headers

```

```

## NAME

Ns\_ConnCondSetHeaders, Ns\_ConnSetExpiresHeader, Ns\_ConnSetHeaders, Ns\_ConnSetLastModifiedHeader, Ns\_ConnSetLengthHeader, Ns\_ConnSetRequiredHeaders - Routines to manage response headers

## SYNOPSIS

```
#include "ns.h"

void
Ns_ConnCondSetHeaders(conn, key, value)

void
Ns_ConnSetExpiresHeader(conn, expires)

void
Ns_ConnSetHeaders(conn, key, value)

void
Ns_ConnSetLastModifiedHeader(conn, mtime)

void
Ns_ConnSetLengthHeader(conn, length)

void
Ns_ConnSetRequiredHeaders(conn, type, length)

void
Ns_ConnSetTypeHeader(conn, type)
```

## ARGUMENTS

- Ns\_Conn *conn* (in)

  Pointer to open connection.

- char *\*expires* (in)

  Pointer to string to construct an *expires* header.

- char *\*key* (in)

  Pointer to string key for a header.

- int *length* (in)

  Integer length of output content to construct a *content-length* header.

- time\_t *mtime* (in)

  Modification time stamp to construct a *last-modified* header.

- int *status* (in)

  HTTP result status code.

- char *\*type* (in)

  Pointer to mimetype string to construct a *content-type* header.

- char *\*value* (in)

  Pointer to a string value for a header.

  ```

  ```

## DESCRIPTION

These functions manage the output headers eventually sent through the given open connection to a client.  They operate by modifying the *outputheaders* Ns\_Set of the connection Ns\_Conn structure. Headers can be modified until they are queued or sent directly via the **Ns\_ConnQueueHeaders** or **Ns\_ConnFlushHeaders** routines. It is possible to modify the *outputheaders* directly although use of these functions is preferred for consistancy.

Note that higher level output routines such as **Ns\_ConnFlush** or the various **Ns\_ConnReturn** routines normally generate all the headers necessary for a given response.  These routines are normally only necessary for specialized applications which output additional specific headers or specialized request procedures which do not use the higher level output routines.

- void **Ns\_ConnCondSetHeaders**(*conn, key, value*)

  Append an output header of the form *key: value* only if the header does not already exist in the *outputheaders* set.

- void **Ns\_ConnSetExpiresHeader**(*conn, expires*)

  This routine is equivalent to **Ns\_ConnSetHeaders**(*conn,* *"Expires", expires*).  Note that the *exires* parameter is treated as a string, not a timestamp.  A timestamp can be constructed with the **Ns\_HttpTime** routine.

- void **Ns\_ConnSetHeaders**(*conn, key, value*)

  Append a header of the form *key: value* to the *outputheaders*. This routine will append a new, possibly duplicate, header regardless of whether a matching header already exists in the *outputheaders*.

- void **Ns\_ConnSetLastModifiedHeader**(*conn, mtime*)

  This routine appends a *last-modified* header if one does not already exists, formatting the given modification time as a proper HTTP timestamp with the **Ns\_HttpTime** routine.

- void **Ns\_ConnSetLengthHeader**(*conn, length*)

  This routine appends a *content-length: length* header, formatting the given integer length as a string.  This routine will also record the response length internally in the *conn* structure so that it can be later retrieved via the **Ns\_ConnResponseLength** routine, for example, as part of a post-connection logging callback.

- void **Ns\_ConnSetRequiredHeaders**(*conn, type, length*)

  This routine appends the basic headers normally required for a proper HTTP transaction.  These include *mime-version*, *date*, and *server* as well as the *content-type: type* and *content-length: length* headers for the given arguments.  If *type* is NULL or *length* is less than zero, the corresponding headers will not be appended.  This routine is often the only header construction routine necessary for request procedures which construct headers manually instead of calling routines such as **Ns\_ConnFlush** which handle header construction and queueing automatically.

- void **Ns\_ConnSetTypeHeader**(*conn, type*)

  This routine is equivalent to **Ns\_ConnSetHeaders**(*conn,* *"content-type", type*).

## SEE ALSO

[Ns\_ConnQueueHeaders(3)](/Ns_ConnQueueHeaders/3.md), [Ns\_ConnFlushHeaders(3)](/Ns_ConnFlushHeaders/3.md), Ns\_ConnFlush(3)

## KEYWORDS

headers, response
