posts

How to access custom headers in Hummingbird 2

A quick example of how to access custom headers in the Swift Server platform Hummingbird.

Hummingbird is a server framework written in Swift. I’m using it at work and for a few personal projects. It’s small and quick to build, so it checks the boxes for what I’m trying to do.

The Hummingbird project is quickly moving to v2.0 (as of writing this RC 2 is out 🎉), and that brought a change with accessing custom headers. In v1 it looked something like request.headers["custom-header-name"]. In v2 it now requires a bit more work thanks to the reliance on Swift-HTTP-Types, but ultimately I think it’s a cleaner call site.

First, you need to extend HTTPField.name and add the new header name in there.

// don't forget to import HTTPTypes
import HTTPTypes

extension HTTPField.Name {
  // if you don't force unwrap here, you'll need to account for the optional in the next step
	static let customHeaderName = Self("custom-header-name")!
}

Then you can call it in a very similar way to v1.

let headerValue = request.headers[.customHeaderName]
Jun 10, 2026 swifthummingbirdrailwayswift concurrency
Fixing Hummingbird Logs on Railway
I deployed a perfectly healthy Hummingbird server to Railway and every log line showed up red: info, debug, all of it tagged as an error. Here's why it happens and how I walked through fixing it.
May 13, 2026 swiftcore dataswift concurrency
Stop Using @MainActor as a Threading Fix for Core Data async/await
Using `@MainActor` to silence Core Data concurrency errors keeps service-layer work on the main thread. Learn how `newBackgroundContext()` and `context.perform` create a safer async/await pattern.
Nov 9, 2025 swiftswift testing
How to run Swift Tests Serially across files
Here's how I am running Swift Tests serially. Note, this is using Swift Testing.