Files
swift-nio/Sources/NIOHTTP1Server
419f57f136 Winsock Fixes (#3433)
This PR gets TCP (Servers) on Windows mostly working. I'll annotate my
PR for clarity.

**The one bug:**
If you open a TCP client connection to a Windows TCP server, it doesn't
read/write yet until a second connection comes in. This happens because
`reregister0` is called after `WSAPoll` is called - but WSAPoll isn't
woken up to know this so it doesn't know the new socket requests
read/writes/...

Also the EventLoop cannot be woken up during `el.execute { .. }` because
`SleepEx` isn't running. WSAPoll doesn't respond to this signal it
seems.

This makes the TCP server functionality not yet usable, but I thought
with this draft we could figure out what I'm missing.

Alternative considered: We can make `WSAPoll` limited to wake up every 1
ms for example, that way we can still get to these events at _some_
point.

---------

Co-authored-by: Cory Benfield <lukasa@apple.com>
Co-authored-by: Fabian Fett <fabianfett@apple.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: Oliver Drobnik <oliver@cocoanetics.com>
Co-authored-by: Jake Petroules <jake.petroules@apple.com>
Co-authored-by: George Barnett <gbarnett@apple.com>
Co-authored-by: Gabriele Mondada <gab@ijk.ch>
2026-07-07 15:46:28 +01:00
..
2026-07-07 15:46:28 +01:00

NIOHTTP1Server

This sample application provides a HTTP server that supports a number of query methods for testing purposes. Invoke it using one of the following syntaxes:

swift run NIOHTTP1Server  # Binds the server on ::1, port 8888.
swift run NIOHTTP1Server 8988  # Binds the server on ::1, port 8988
swift run NIOHTTP1Server /path/to/unix/socket  # Binds the server using the given UNIX socket
swift run NIOHTTP1Server 192.168.0.5 8988  # Binds the server on 192.168.0.5:8988

The final three syntaxes optionally accept an additional argument, a path to a directory of files to serve from the webserver. The first syntax does not, as that would conflict with the UNIX socket path syntax.

So, for example, to spin up a local webserver on port 80 serving a specific directory, you can run:

swift run NIOHTTP1Server localhost 80 /var/www

Paths

The server has the following endpoints:

  • /: serves "Hello world!"
  • /sendfile/*: serves the file at path * to the client, using sendfile.
  • /fileio/*: serves the file at path * to the client by reading the file in to memory in chunks.
  • /dynamic/echo: Echoes the request body back to the client.
  • /dynamic/echo_balloon: Echoes the request body back to the client after buffering it entirely in memory first.
  • /dynamic/pid: Echoes pack the PID of the server.
  • /dynamic/write-delay: Echoes "Hello world" after a 100ms delay.
  • /dynamic/info: Sends information about the received request.
  • /dynamic/trailers: Sends the PID along with some HTTP trailers.
  • /dynamic/continuous: Sends a chunked body forever.
  • /dynamic/count-to-ten: Sends the numbers 1 through 10 in separate chunks.
  • /dynamic/client-ip: Sends what the server believes the client IP is.