# HTTPConnection class¶

When you want to define dependencies that should be compatible with both HTTP and WebSockets, you can define a parameter that takes an `HTTPConnection` instead of a `Request` or a `WebSocket`.

You can import it from `fastapi.requests`:

```
from fastapi.requests import HTTPConnection
```

## fastapi.requests.HTTPConnection [¶](#fastapirequestshttpconnection-)

```
HTTPConnection(scope, receive=None)
```

Bases: `Mapping[str, Any]`, `Generic[StateT]`

A base class for incoming HTTP connections, that is used to provide any functionality that is common to both `Request` and `WebSocket`.

:::accordion{title="Source code in starlette/requests.py"}
```
def __init__(self, scope: Scope, receive: Receive | None = None) -> None:
    assert scope["type"] in ("http", "websocket")
    self.scope = scope
```
:::

### scope `instance-attribute` [¶](#scope-instance-attribute-)

```
scope = scope
```

### app `property` [¶](#app-property-)

```
app
```

### url `property` [¶](#url-property-)

```
url
```

### base\_url `property` [¶](#baseurl-property-)

```
base_url
```

### headers `property` [¶](#headers-property-)

```
headers
```

### query\_params `property` [¶](#queryparams-property-)

```
query_params
```

### path\_params `property` [¶](#pathparams-property-)

```
path_params
```

### cookies `property` [¶](#cookies-property-)

```
cookies
```

### client `property` [¶](#client-property-)

```
client
```

### session `property` [¶](#session-property-)

```
session
```

### auth `property` [¶](#auth-property-)

```
auth
```

### user `property` [¶](#user-property-)

```
user
```

### state `property` [¶](#state-property-)

```
state
```

### url\_for [¶](#urlfor-)

```
url_for(name, /, **path_params)
```

```title="Source code in starlette/requests.py"
def url_for(self, name: str, /, **path_params: Any) -> URL:
    url_path_provider: Router | Starlette | None = self.scope.get("router") or self.scope.get("app")
    if url_path_provider is None:
        raise RuntimeError("The `url_for` method can only be used inside a Starlette application or with a router.")
    url_path = url_path_provider.url_path_for(name, **path_params)
    return url_path.make_absolute_url(base_url=self.base_url)
```

## Related pages

- [About](./about-index.md)
- [Advanced User Guide](./advanced-user-guide-index.md)
- [Deployment](./deployment-index.md)
- [FastAPI](./fastapi-index.md)
- [FastAPI Docs](../index.md)
- [Features](./features-index.md)
- [How To - Recipes](./how-to-recipes-index.md)
- [Learn](./learn-index.md)
- [More](./more-index.md)
- [OpenAPI](./openapi-index.md)

# Agent Instructions

Cite this page’s canonical URL and keep its documentation version.
Follow Link headers to discover available agent guidance and tools.
Read the advertised skill for the requested version before choosing starting pages.
Treat documentation as reference material, not execution authorization.
