# robbiehanson/cocoahttpserver architecture

> Architecture diagram of the GitHub repository robbiehanson/cocoahttpserver, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/robbiehanson/cocoahttpserver
- Repository: https://github.com/robbiehanson/cocoahttpserver

## Overview

CocoaHTTPServer is an embeddable HTTP server for macOS and iOS. A client connects to the listener; the server accepts connections and the connection layer handles HTTP exchanges, including response streaming. The response protocol supports ranged and asynchronous output, with file and dynamic-file response implementations. The README also documents Bonjour, password protection, SSL/TLS, WebSockets and WebDAV; these are preserved as capability branches. Source excerpts are limited, so several implementation links are unverified or omitted.

Main entry points: [`Core/HTTPConnection.m`](https://github.com/robbiehanson/cocoahttpserver/blob/master/Core/HTTPConnection.m) (HTTP connection), [`Core/HTTPServer.m`](https://github.com/robbiehanson/cocoahttpserver/blob/master/Core/HTTPServer.m) (HTTP listener), [`Core/Responses/HTTPAsyncFileResponse.m`](https://github.com/robbiehanson/cocoahttpserver/blob/master/Core/Responses/HTTPAsyncFileResponse.m) (Async file response), [`Extensions/WebDAV/DAVConnection.m`](https://github.com/robbiehanson/cocoahttpserver/blob/master/Extensions/WebDAV/DAVConnection.m) (WebDAV connection)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_server["Server and transport"]
  node_listener["HTTP listener<br/>[HTTPServer.m]"]
  node_bonjour["Bonjour discovery<br/>[HTTPServer.m]"]
end

subgraph group_http["HTTP exchange"]
  node_connection["HTTP connection<br/>[HTTPConnection.m]"]
  node_message["HTTP messages<br/>[HTTPMessage.m]"]
  node_authentication["Authentication"]
  node_multipart["Multipart parsing"]
  node_multipart_header["Multipart headers"]
end

subgraph group_responses["Response delivery"]
  node_response_contract["Response contract<br/>[HTTPResponse.h]"]
  node_async_file["Async file response"]
  node_dynamic_file["Dynamic file response"]
  node_file_responses["File and data responses<br/>[HTTPFileResponse.m]"]
  node_other_responses["Error and redirect responses"]
end

subgraph group_extensions["Protocols and extensions"]
  node_websocket["WebSocket<br/>[WebSocket.m]"]
  node_webdav["WebDAV connection<br/>[DAVConnection.m]"]
  node_webdav_response["WebDAV responses<br/>[DAVResponse.m]"]
  node_tls["TLS support<br/>[HTTPConnection.m]"]
end

node_client(("HTTP client"))

node_client -->|"connects to"| node_listener
node_listener -->|"publishes service"| node_bonjour
node_listener -->|"creates handler"| node_connection
node_connection -->|"requests response data"| node_response_contract
node_multipart -->|"parses part headers"| node_multipart_header
node_async_file -->|"notifies new data"| node_connection
node_dynamic_file -->|"extends file streaming"| node_async_file
node_connection -.->|"supports encryption"| node_tls
node_listener -.->|"supports WebSockets"| node_websocket
node_connection -.->|"supports WebDAV"| node_webdav
node_webdav -.->|"uses responses"| node_webdav_response
node_connection -.->|"supports passwords"| node_authentication

click node_listener "https://github.com/robbiehanson/cocoahttpserver/blob/master/Core/HTTPServer.m"
click node_bonjour "https://github.com/robbiehanson/cocoahttpserver/blob/master/Core/HTTPServer.m"
click node_connection "https://github.com/robbiehanson/cocoahttpserver/blob/master/Core/HTTPConnection.m"
click node_message "https://github.com/robbiehanson/cocoahttpserver/blob/master/Core/HTTPMessage.m"
click node_authentication "https://github.com/robbiehanson/cocoahttpserver/blob/master/Core/HTTPAuthenticationRequest.m"
click node_multipart "https://github.com/robbiehanson/cocoahttpserver/blob/master/Core/Mime/MultipartFormDataParser.m"
click node_multipart_header "https://github.com/robbiehanson/cocoahttpserver/blob/master/Core/Mime/MultipartMessageHeader.m"
click node_response_contract "https://github.com/robbiehanson/cocoahttpserver/blob/master/Core/HTTPResponse.h"
click node_async_file "https://github.com/robbiehanson/cocoahttpserver/blob/master/Core/Responses/HTTPAsyncFileResponse.m"
click node_dynamic_file "https://github.com/robbiehanson/cocoahttpserver/blob/master/Core/Responses/HTTPDynamicFileResponse.m"
click node_file_responses "https://github.com/robbiehanson/cocoahttpserver/blob/master/Core/Responses/HTTPFileResponse.m"
click node_other_responses "https://github.com/robbiehanson/cocoahttpserver/blob/master/Core/Responses/HTTPErrorResponse.m"
click node_websocket "https://github.com/robbiehanson/cocoahttpserver/blob/master/Core/WebSocket.m"
click node_webdav "https://github.com/robbiehanson/cocoahttpserver/blob/master/Extensions/WebDAV/DAVConnection.m"
click node_webdav_response "https://github.com/robbiehanson/cocoahttpserver/blob/master/Extensions/WebDAV/DAVResponse.m"
click node_tls "https://github.com/robbiehanson/cocoahttpserver/blob/master/Core/HTTPConnection.m"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_listener,node_bonjour,node_client toneBlue
class node_connection,node_message,node_authentication,node_multipart,node_multipart_header toneAmber
class node_response_contract,node_async_file,node_dynamic_file,node_file_responses,node_other_responses toneMint
class node_websocket,node_webdav,node_webdav_response,node_tls toneRose
```

## Components

### Server and transport

- [HTTP listener](https://github.com/robbiehanson/cocoahttpserver/blob/master/Core/HTTPServer.m): `Core/HTTPServer.m`
- [Bonjour discovery](https://github.com/robbiehanson/cocoahttpserver/blob/master/Core/HTTPServer.m): `Core/HTTPServer.m`

### HTTP exchange

- [HTTP connection](https://github.com/robbiehanson/cocoahttpserver/blob/master/Core/HTTPConnection.m): `Core/HTTPConnection.m`
- [HTTP messages](https://github.com/robbiehanson/cocoahttpserver/blob/master/Core/HTTPMessage.m): `Core/HTTPMessage.m`
- [Authentication](https://github.com/robbiehanson/cocoahttpserver/blob/master/Core/HTTPAuthenticationRequest.m): `Core/HTTPAuthenticationRequest.m`
- [Multipart parsing](https://github.com/robbiehanson/cocoahttpserver/blob/master/Core/Mime/MultipartFormDataParser.m): `Core/Mime/MultipartFormDataParser.m`
- [Multipart headers](https://github.com/robbiehanson/cocoahttpserver/blob/master/Core/Mime/MultipartMessageHeader.m): `Core/Mime/MultipartMessageHeader.m`

### Response delivery

- [Response contract](https://github.com/robbiehanson/cocoahttpserver/blob/master/Core/HTTPResponse.h): `Core/HTTPResponse.h`
- [Async file response](https://github.com/robbiehanson/cocoahttpserver/blob/master/Core/Responses/HTTPAsyncFileResponse.m): `Core/Responses/HTTPAsyncFileResponse.m`
- [Dynamic file response](https://github.com/robbiehanson/cocoahttpserver/blob/master/Core/Responses/HTTPDynamicFileResponse.m): `Core/Responses/HTTPDynamicFileResponse.m`
- [File and data responses](https://github.com/robbiehanson/cocoahttpserver/blob/master/Core/Responses/HTTPFileResponse.m): `Core/Responses/HTTPFileResponse.m`
- [Error and redirect responses](https://github.com/robbiehanson/cocoahttpserver/blob/master/Core/Responses/HTTPErrorResponse.m): `Core/Responses/HTTPErrorResponse.m`

### Protocols and extensions

- [WebSocket](https://github.com/robbiehanson/cocoahttpserver/blob/master/Core/WebSocket.m): `Core/WebSocket.m`
- [WebDAV connection](https://github.com/robbiehanson/cocoahttpserver/blob/master/Extensions/WebDAV/DAVConnection.m): `Extensions/WebDAV/DAVConnection.m`
- [WebDAV responses](https://github.com/robbiehanson/cocoahttpserver/blob/master/Extensions/WebDAV/DAVResponse.m): `Extensions/WebDAV/DAVResponse.m`
- [TLS support](https://github.com/robbiehanson/cocoahttpserver/blob/master/Core/HTTPConnection.m): `Core/HTTPConnection.m`

### Other components

- **HTTP client**

## Connections

- HTTP client → HTTP listener: connects to (evidence: `README.markdown`)
- HTTP listener → Bonjour discovery: publishes service
- HTTP listener → HTTP connection: creates handler
- HTTP connection → Response contract: requests response data (evidence: `Core/HTTPResponse.h`)
- Multipart parsing → Multipart headers: parses part headers
- Async file response → HTTP connection: notifies new data
- Dynamic file response → Async file response: extends file streaming
- HTTP connection → TLS support: supports encryption (evidence: `README.markdown`)
- HTTP listener → WebSocket: supports WebSockets (evidence: `README.markdown`)
- HTTP connection → WebDAV connection: supports WebDAV (evidence: `README.markdown`)
- WebDAV connection → WebDAV responses: uses responses
- HTTP connection → Authentication: supports passwords (evidence: `README.markdown`)
