---
title: MockHttpServer
summary: Local HTTP server for backend testing.
url: https://www.fastly.com/documentation/reference/compute/sdks/python/fastly_compute/testing/mock_http_server/class.MockHttpServer/
---

**Kind:** Class  
**Module:** [mock_http_server](https://www.fastly.com/documentation/reference/compute/sdks/python/fastly_compute/testing/mock_http_server/)  
**Package:** fastly-compute 0.1.3  
**Source:** https://github.com/fastly/compute-sdk-python/blob/2bffcc6d596a68bcc0b4342404641deff78e68f6/fastly_compute/testing/mock_http_server.py#L129

Local HTTP server for backend testing.

This server can be used to mock external backends during testing.
It supports both httpbin-style behavior and custom response patterns.

## Constructor

**Source:** https://github.com/fastly/compute-sdk-python/blob/2bffcc6d596a68bcc0b4342404641deff78e68f6/fastly_compute/testing/mock_http_server.py#L136

```python
MockHttpServer(host: str = '127.0.0.1', port: int = 0, responses: dict[str, dict[str, Any]] | None = None)
```

Initialize the test server.

**Parameters**

- `host`: `str` (optional) = `'127.0.0.1'` — The host interface to bind to (default: "127.0.0.1")
- `port`: `int` (optional) = `0` — The port to bind to (default: 0 for auto-assignment)
- `responses`: `dict[str, dict[str, Any]] | None` (optional) = `None`

  Optional dict mapping paths to response configs.
  Each response config can contain...

  "status"
      HTTP status code (default: 200)
  "headers"
      Dict of HTTP headers
  "body"
      Response body (dict will be JSON-encoded)

  Example::

      {"/api/test": {"status": 200, "body": {"success": True}}}

## Properties

### base_url

**Type:** `str`  
**Flags:** read-only  
**Source:** https://github.com/fastly/compute-sdk-python/blob/2bffcc6d596a68bcc0b4342404641deff78e68f6/fastly_compute/testing/mock_http_server.py#L216

Get the base URL of the running server.

## Methods

### __enter__

**Source:** https://github.com/fastly/compute-sdk-python/blob/2bffcc6d596a68bcc0b4342404641deff78e68f6/fastly_compute/testing/mock_http_server.py#L207

```python
__enter__()
```

Context manager entry.

### __exit__

**Source:** https://github.com/fastly/compute-sdk-python/blob/2bffcc6d596a68bcc0b4342404641deff78e68f6/fastly_compute/testing/mock_http_server.py#L211

```python
__exit__(exc_type, exc_val, exc_tb)
```

Context manager exit.

**Parameters**

- `exc_type`: `Any`
- `exc_val`: `Any`
- `exc_tb`: `Any`

### start

**Source:** https://github.com/fastly/compute-sdk-python/blob/2bffcc6d596a68bcc0b4342404641deff78e68f6/fastly_compute/testing/mock_http_server.py#L166

```python
start() -> str
```

Start the test server.

**Returns**

`str`

The base URL of the started server (e.g., "http://127.0.0.1:12345")

### stop

**Source:** https://github.com/fastly/compute-sdk-python/blob/2bffcc6d596a68bcc0b4342404641deff78e68f6/fastly_compute/testing/mock_http_server.py#L194

```python
stop()
```

Stop the test server.
