Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Sources/Hummingbird/Deprecations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ public typealias HBApplicationConfiguration = ApplicationConfiguration
public typealias HBApplicationProtocol = ApplicationProtocol
@_documentation(visibility: internal) @available(*, unavailable, renamed: "Environment")
public typealias HBEnvironment = Environment

#if !os(Windows)
@_documentation(visibility: internal) @available(*, unavailable, renamed: "FileIO")
public typealias HBFileIO = FileIO
#endif

@_documentation(visibility: internal) @available(*, unavailable, renamed: "RequestContext")
public typealias HBBaseRequestContext = RequestContext
Expand Down Expand Up @@ -62,8 +65,10 @@ public typealias HBRouterPath = RouterPath

@_documentation(visibility: internal) @available(*, unavailable, renamed: "CORSMiddleware")
public typealias HBCORSMiddleware = CORSMiddleware
#if !os(Windows)
@_documentation(visibility: internal) @available(*, unavailable, renamed: "FileMiddleware")
public typealias HBFileMiddleware = FileMiddleware
#endif
@_documentation(visibility: internal) @available(*, unavailable, renamed: "LogRequestsMiddleware")
public typealias HBLogRequestsMiddleware = LogRequestsMiddleware
@_documentation(visibility: internal) @available(*, unavailable, renamed: "MetricsMiddleware")
Expand Down
15 changes: 15 additions & 0 deletions Sources/Hummingbird/Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ import Musl
import Darwin.C
#elseif canImport(Android)
import Android
#elseif canImport(ucrt)
import ucrt
import WinSDK
#else
#error("Unsupported platform")
#endif
Expand Down Expand Up @@ -139,9 +142,17 @@ public struct Environment: Sendable, Decodable, ExpressibleByDictionaryLiteral {
public mutating func set(_ s: String, value: String?) {
self.values[s.lowercased()] = value
if let value {
#if os(Windows)
_putenv("\(s)=\(value)")
#else
setenv(s, value, 1)
#endif
} else {
#if os(Windows)
_putenv("\(s)=")
#else
unsetenv(s)
#endif
}
}

Expand Down Expand Up @@ -180,7 +191,11 @@ public struct Environment: Sendable, Decodable, ExpressibleByDictionaryLiteral {
let contents = try fileHandle.withUnsafeFileDescriptor { descriptor in
[UInt8](unsafeUninitializedCapacity: fileRegion.readableBytes) { bytes, size in
size = fileRegion.readableBytes
#if os(Windows)
read(descriptor, .init(bytes.baseAddress), UInt32(size))
#else
read(descriptor, .init(bytes.baseAddress), size)
#endif
}
}
return String(bytes: contents, encoding: .utf8)
Expand Down
2 changes: 2 additions & 0 deletions Sources/Hummingbird/Files/FileIO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
//
//===----------------------------------------------------------------------===//

#if !os(Windows)
import CNIOLinux
public import HummingbirdCore
import Logging
Expand Down Expand Up @@ -157,3 +158,4 @@ extension NonBlockingFileIO {
}
}
}
#endif
2 changes: 2 additions & 0 deletions Sources/Hummingbird/Files/LocalFileSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
//
//===----------------------------------------------------------------------===//

#if !os(Windows)
public import Logging
public import NIOPosix

Expand Down Expand Up @@ -126,3 +127,4 @@ public struct LocalFileSystem: FileProvider {
try await self.fileIO.loadFile(path: path, range: range, context: context)
}
}
#endif
2 changes: 2 additions & 0 deletions Sources/Hummingbird/Middleware/FileMiddleware.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
//
//===----------------------------------------------------------------------===//

#if !os(Windows)
import HTTPTypes
public import HummingbirdCore
public import Logging
Expand Down Expand Up @@ -402,3 +403,4 @@ extension FileMiddleware {
return nil
}
}
#endif
3 changes: 3 additions & 0 deletions Sources/PerformanceTest/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ let port = env.get("SERVER_PORT", as: Int.self) ?? 8080
// create app
let elg = MultiThreadedEventLoopGroup(numberOfThreads: 4)
var router = Router()

#if !os(Windows)
router.addMiddleware {
FileMiddleware()
}
#endif

// number of raw requests
// ./wrk -c 128 -d 15s -t 8 http://localhost:8080
Expand Down
Loading