---
name: "Ns_ConnGetType"
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_ConnGetType"
---

# Ns\_ConnGetType(3aolserver)

Routines to manage the HTTP response type

```

```

## NAME

Ns\_ConnGetType, Ns\_ConnSetType - Routines to manage the HTTP response type

## SYNOPSIS

```
#include "ns.h"

char *
Ns_ConnGetType(conn)

void
Ns_ConnSetType(conn, type)
```

## ARGUMENTS

- Ns\_Conn *conn* (in)

  Pointer to open connection.

- char *\*type* (in)

  Character string with response mimetype.

  ```

  ```

## DESCRIPTION

These routines both manage the eventual *content-type* header which is generated by a later call to **Ns\_ConnFlush** or **Ns\_ConnFlushDirect** as well as manage the appropriate character encoding for text output types.

- char \***Ns\_ConnGetType**(*conn*)

  Return the current HTTP mime type (e.g., "text/html; charset=iso-8859-1") or NULL if no type has yet been set.

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

  Sets the mimetype of the response to the given *type*.  A later call to **Ns\_ConnFlush** will include a header of the form *content-type: type* when generating the response.

## CHARSETS AND ENCODINGS

For text types, a call to **Ns\_ConnSetType** can also include an optional "charset=" attribute.  If no *charset* is specified, the server will append a default charset if specified as the *outputcharset* server configuration variable.

With a given or automatically appended charset for text types, the server will then set the output encoding to the cooresponding Tcl\_Encoding, for example, mapping the charset "iso-8859-1" to the Tcl\_Encoding equivalent "iso8859-1".  All text later sent via  **Ns\_ConnFlush** will be first encoded using the determined Tcl\_Encoding (calls to **Ns\_ConnFlushDirect** will bypass this encoding step).  See the man pages on **Ns\_GetCharsetEncoding** for details on how these mappings are configured.

The charset modification feature was added in later versions of AOLserver to support legacy code which may have been sprinkled with direct calls to set text types without specifying the charset, e.g., calls such as:

```
	ns_return 200 text/html "<body>hello</body>"
```

## EXAMPLES

The following example demonstrates sending Japanese character data. In this case, assume "utf8string" contains a series of UTF-8 bytes with various Japanese characters.  The call to **Ns\_ConnSetType** will setup the appropriate "shiftjis" output Tcl\_Encoding to match the given "shift\_jis" charset:

```
	Ns_ConnSetStatus(conn, 200);
	Ns_ConnSetType(conn, "text/html; charset=shift_jis");
	Ns_ConnFlushDirect(conn, utf8string, -1, 0);
```

The following demonstrates the behavior of the default server charset encoding.  Assume the following is set in the config file:

```
	ns_section ns/server/serverName
	ns_param outputcharset iso-8859-1
```

In this case, a call to **Ns\_ConnSetType**(*conn, "text/html"*) without a specific charset would be modified to include "charset=iso-8859-1".  Based on this modification, the output encoding would be set to the "iso8859-1" Tcl\_Encoding.

## SEE ALSO

Ns\_ConnGetType(3), Ns\_ConnSetType(3), Ns\_ConnFlush(3), Ns\_ConnFlushDirect(3), [Ns\_ConnSetRequiredHeaders(3)](/Ns_ConnSetRequiredHeaders/3.md), [Ns\_ConnQueueHeaders(3)](/Ns_ConnQueueHeaders/3.md), [Ns\_GetCharsetEncoding(3)](/Ns_GetCharsetEncoding/3.md), [Ns\_GetTypeEncoding(3)](/Ns_GetTypeEncoding/3.md), ns\_conn(n)

## KEYWORDS

connectionn, response, status, encoding, charset
