Skip to content

Releases: swhitty/FlyingFox

Route Parameters

13 Jul 23:46
b37b5ab
Compare
Choose a tag to compare
  • Adds route parameters (🙏🏻 @tonyarnold)
  • HTTPRoute now matches methods against Set<HTTPMethod>
  • Replaces AsyncChunkedSequence with AsyncBufferedSequence
  • Support for Transfer-Encoding: chunked for responses without a known size

Route Parameters

Routes can include named parameters within a path or query item using the : prefix. Any string supplied to this parameter will match the route, handlers can access the value of the string using request.routePamaters.

handler.appendRoute("GET /creature/:name?type=:beast") { request in
  let name = request.routeParameters["name"]
  let beast = request.routeParameters["beast"]
  return HTTPResponse(statusCode: .ok)
}

When using Swift 5.9+, route parameters can be automatically extracted and mapped to closure parameters of handlers.

enum Beast: String, HTTPRouteParameterValue {
  case fish
  case dog
}

handler.appendRoute("GET /creature/:name?type=:beast") { (name: String, beast: Beast) -> HTTPResponse in
  return HTTPResponse(statusCode: .ok)
}

The request can be optionally included.

handler.appendRoute("GET /creature/:name?type=:beast") { (request: HTTPRequest, name: String, beast: Beast) -> HTTPResponse in
  return HTTPResponse(statusCode: .ok)
}

String, Int, Double, Bool and any type that conforms to HTTPRouteParameterValue can be extracted.

0.14.0 RangeReplaceableCollection

14 Apr 08:46
c9e0d35
Compare
Choose a tag to compare

Fix Percent Encoded Paths Swift 5.7+

24 Nov 06:57
00e4d51
Compare
Choose a tag to compare
  • Fixes support for parsing and matching requests and routes with percent encoded paths. #74 Thanks @wirrareka
  • Drops support for Swift 5.5 and 5.6.

Fix crash in HTTPServer.stop()

24 Oct 07:19
8a20a97
Compare
Choose a tag to compare
  • Fixes a crash in HTTPServer.stop() ensuring socket is not closed twice #66
    🙏🏻 Thanks @samlapse

Fix Buffer leak

18 Aug 23:16
ed86fc6
Compare
Choose a tag to compare
  • Initial support Swift 5.9
  • Fixes a small buffer leak #62. 🙏🏻 Thanks @lhoward

Initial Support for Swift 5.9 & DiscardingTaskGroup

29 Jun 06:10
8b195ab
Compare
Choose a tag to compare
  • Adds support for Swift 5.9 and DiscardingTaskGroup (when available). #60
  • Xcode 15 Beta 2 support
  • Support image/x-icon, image/webp, image/jp2 Content-Type.

Initial Support for Swift 5.9 & DiscardingTaskGroup

16 Jun 03:39
1169214
Compare
Choose a tag to compare
  • Adds support for Swift 5.9 and DiscardingTaskGroup (when available). #60
  • isListening public API #59
  • Support image/svg+xml Content-Type.

Large Requests with HTTPBodySequence

03 Apr 01:35
7488f1e
Compare
Choose a tag to compare

Adds support for very large bodies within HTTPRequest and HTTPResponse that can be processed in Data chunks.

HTTPRequest

Requests now include a bodySequence: HTTPBodySequence which allows the request body to be iterated in small chunks as they arrive:

func saveBody(request: HTTPRequest) async throws -> HTTPResponse {
  let file = URL(fileURLWithPath: "/tmp/file")
  _ = FileManager.default.createFile(atPath: file.path, contents: nil)
  let handle = try FileHandle(forWritingTo: file)
  for try await chunk in req.bodySequence {
    try handle.write(contentsOf: chunk)
  }
  return HTTPResponse(statusCode: .ok)
}

The existing var data: Data property has been deprecated, but is still supported and synchronously returns the uploaded data for requests less than 10 MiB.

HTTPResponse

Response payloads can provide a HTTPBodySequence which allows the response body to be provided in small chunks as they are sent:

func getXcode(request: HTTPRequest) async throws -> HTTPResponse {
  try HTTPResponse(
    statusCode: .ok,
    body: HTTPBodySequence(file: URL(fileURLWithPath: "/tmp/Xcode_14.3.xip"))
  )
}

Providing a Data instance for the body property is still supported.

The existing var data: Data? property has been deprecated, but is still supported and synchronously returns response payload if the response is not a web socket or HTTPBodySequence.

FileHTTPHandler

The existing FileHTTPHandler now serves all files larger than 10 MiB in small chunks, while files smaller are still served via a complete Data instance.

Large Requests with HTTPBodySequence

03 Apr 00:22
96d7101
Compare
Choose a tag to compare

Adds support for very large bodies within HTTPRequest and HTTPResponse that can be processed in Data chunks.

HTTPRequest

Requests now include a bodySequence: HTTPBodySequence which allows the request body to be iterated in small chunks as the arrive:

func saveBody(request: HTTPRequest) async throws -> HTTPResponse {
  let file = URL(fileURLWithPath: "/tmp/file")
  _ = FileManager.default.createFile(atPath: file.path, contents: nil)
  let handle = try FileHandle(forWritingTo: file)
  for try await chunk in req.bodySequence {
    try handle.write(contentsOf: chunk)
  }
  return HTTPResponse(statusCode: .ok)
}

The existing var data: Data property has been deprecated, but is still supported and synchronously returns the uploaded data for requests less than 10 MiB.

HTTPResponse

Response payloads can provide a HTTPBodySequence which allows the response body to be provided in small chunks as they are sent:

func getXcode(request: HTTPRequest) async throws -> HTTPResponse {
  try HTTPResponse(
    statusCode: .ok,
    body: HTTPBodySequence(file: URL(fileURLWithPath: "/tmp/Xcode_14.3.xip"))
  )
}

Providing a Data instance for the body property is still supported.

The existing var data: Data? property has been deprecated, but is still supported and synchronously returns response payload if the response is not a web socket or HTTPBodySequence.

FileHTTPHandler

The existing FileHTTPHandler now serves all files larger than 10 MiB in small chunks, while files smaller are still served via a complete Data instance.

SocketPool kqueue / epoll

18 Oct 07:13
8ef9edd
Compare
Choose a tag to compare
  • kqueue(2) / epoll(7) events are now used to suspend and resume socket using SocketPool<EventQueue>
  • SocketPool<EventQueue> is now the default pool used by HTTPServer
  • PollingSocketPool has been replaced by SocketPool<Poll>
  • Windows uses SocketPool<Poll>
  • Moved HTTPLogging to FlyingSocks.Logging enabling logs within sockets and pools.
  • Decreased compilation time