# ServerResponder

<a id="serverresponder"></a>

# ServerResponder

```cpp
#include <icy/http/server.h>

class ServerResponder
```

[Defined in src/http/include/icy/http/server.h:146](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/server.h#L146)

Base responder interface for handling one HTTP request on a server connection. Derived classes typically override [`onRequest()`](#onrequest) and optionally the streaming hooks.

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`ServerResponder`](#serverresponder-1) `inline` | Creates a [ServerResponder](#serverresponder) for the given connection. |
|  | [`~ServerResponder`](#serverresponder-2) `virtual` | Defaulted destructor. |
| `void` | [`onHeaders`](#onheaders-3) `virtual` `inline` | Called when the incoming request headers have been parsed. |
| `void` | [`onPayload`](#onpayload-3) `virtual` `inline` | Called for each chunk of incoming request body data. |
| `void` | [`onRequest`](#onrequest) `virtual` `inline` | Called when the complete HTTP request has been received. Derived classes should write their response here. |
| `void` | [`onClose`](#onclose-6) `virtual` `inline` | Called when the connection is closed. |
| [`ServerConnection`](https://auscaster.com/icey/docs/api-reference/icy-http-ServerConnection.md#serverconnection-1) & | [`connection`](#connection-10) `inline` | Returns the underlying server connection. |
| [`Request`](https://auscaster.com/icey/docs/api-reference/icy-http-Request.md#request-6) & | [`request`](#request-12) `inline` | Returns the current HTTP request from the underlying connection. |
| [`Response`](https://auscaster.com/icey/docs/api-reference/icy-http-Response.md#response-3) & | [`response`](#response-10) `inline` | Returns the current HTTP response from the underlying connection. |

---

<a id="serverresponder-1"></a>

### ServerResponder

`inline`

```cpp
inline ServerResponder(ServerConnection & connection)
```

[Defined in src/http/include/icy/http/server.h:151](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/server.h#L151)

Creates a [ServerResponder](#serverresponder) for the given connection.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `connection` | [`ServerConnection`](https://auscaster.com/icey/docs/api-reference/icy-http-ServerConnection.md#serverconnection-1) & | The server connection this responder handles. |

---

<a id="serverresponder-2"></a>

### ~ServerResponder

`virtual`

```cpp
virtual ~ServerResponder() = default
```

[Defined in src/http/include/icy/http/server.h:156](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/server.h#L156)

Defaulted destructor.

---

<a id="onheaders-3"></a>

### onHeaders

`virtual` `inline`

```cpp
virtual inline void onHeaders(Request & request)
```

[Defined in src/http/include/icy/http/server.h:160](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/server.h#L160)

Called when the incoming request headers have been parsed.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `request` | [`Request`](https://auscaster.com/icey/docs/api-reference/icy-http-Request.md#request-6) & | The parsed HTTP request with headers populated. |

---

<a id="onpayload-3"></a>

### onPayload

`virtual` `inline`

```cpp
virtual inline void onPayload(const MutableBuffer & body)
```

[Defined in src/http/include/icy/http/server.h:164](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/server.h#L164)

Called for each chunk of incoming request body data.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `body` | const [`MutableBuffer`](https://auscaster.com/icey/docs/api-reference/icy-MutableBuffer.md#mutablebuffer-6) & | Buffer containing a chunk of the request body. |

---

<a id="onrequest"></a>

### onRequest

`virtual` `inline`

```cpp
virtual inline void onRequest(Request & request, Response & response)
```

[Defined in src/http/include/icy/http/server.h:170](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/server.h#L170)

Called when the complete HTTP request has been received. Derived classes should write their response here.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `request` | [`Request`](https://auscaster.com/icey/docs/api-reference/icy-http-Request.md#request-6) & | The fully received HTTP request. |
| `response` | [`Response`](https://auscaster.com/icey/docs/api-reference/icy-http-Response.md#response-3) & | The HTTP response to populate and send. |

---

<a id="onclose-6"></a>

### onClose

`virtual` `inline`

```cpp
virtual inline void onClose()
```

[Defined in src/http/include/icy/http/server.h:177](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/server.h#L177)

Called when the connection is closed.

---

<a id="connection-10"></a>

### connection

`inline`

```cpp
inline ServerConnection & connection()
```

[Defined in src/http/include/icy/http/server.h:180](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/server.h#L180)

Returns the underlying server connection.

---

<a id="request-12"></a>

### request

`inline`

```cpp
inline Request & request()
```

[Defined in src/http/include/icy/http/server.h:186](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/server.h#L186)

Returns the current HTTP request from the underlying connection.

---

<a id="response-10"></a>

### response

`inline`

```cpp
inline Response & response()
```

[Defined in src/http/include/icy/http/server.h:192](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/server.h#L192)

Returns the current HTTP response from the underlying connection.

## Protected Attributes

| Return | Name | Description |
|--------|------|-------------|
| [`ServerConnection`](https://auscaster.com/icey/docs/api-reference/icy-http-ServerConnection.md#serverconnection-1) & | [`_connection`](#_connection-2)  |  |

---

<a id="_connection-2"></a>

### _connection

```cpp
ServerConnection & _connection
```

Type: [`ServerConnection`](https://auscaster.com/icey/docs/api-reference/icy-http-ServerConnection.md#serverconnection-1) &

[Defined in src/http/include/icy/http/server.h:198](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/server.h#L198)

## Private Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`ServerResponder`](#serverresponder-3)  | Deleted constructor. |
| [`ServerResponder`](#serverresponder) & | [`operator=`](#operator-208)  | Deleted assignment operator. |

---

<a id="serverresponder-3"></a>

### ServerResponder

```cpp
ServerResponder(const ServerResponder &) = delete
```

[Defined in src/http/include/icy/http/server.h:201](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/server.h#L201)

Deleted constructor.

---

<a id="operator-208"></a>

### operator=

```cpp
ServerResponder & operator=(const ServerResponder &) = delete
```

[Defined in src/http/include/icy/http/server.h:202](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/server.h#L202)

Deleted assignment operator.
