Skip to content

Commit 7f821a3

Browse files
committed
Merge branch 'develop'
2 parents c6fa701 + 681512a commit 7f821a3

File tree

4 files changed

+45
-7
lines changed

4 files changed

+45
-7
lines changed

.github/workflows/swift.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
matrix:
1515
image:
1616
- swift:5.9-jammy
17-
- swift:6.1-noble
17+
- swift:6.2-jammy
1818
container: ${{ matrix.image }}
1919
steps:
2020
- name: Checkout Repository
@@ -29,7 +29,7 @@ jobs:
2929
runs-on: macos-latest
3030
steps:
3131
- name: Select latest available Xcode
32-
uses: maxim-lobanov/setup-xcode@v1.5.1
32+
uses: maxim-lobanov/setup-xcode@v1.6.0
3333
with:
3434
xcode-version: latest
3535
- name: Checkout Repository

Sources/http/BasicAuth.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public extension BasicAuthModule {
3838
#if canImport(Foundation) // `String.Encoding.utf8`, provide alternative!
3939
/**
4040
* Extract HTTP Basic authentication credentials (name/pass) from the given
41-
* ```IncomingMessage```.
41+
* ``IncomingMessage``.
4242
*
4343
* - Parameters:
4444
* - request: The ``IncomingMessage`` containing the `Authorization`
@@ -81,7 +81,7 @@ public extension BasicAuthModule {
8181
throw BasicAuthError.differentAuthorization
8282
}
8383

84-
let payload = String(authString[authString.index(after: idx)])
84+
let payload = String(authString[authString.index(after: idx)...])
8585
.trimmingCharacters(in: .whitespacesAndNewlines)
8686

8787
guard let data = Data(base64Encoded: payload) else {
@@ -98,7 +98,7 @@ public extension BasicAuthModule {
9898

9999
return Credentials(
100100
name: String(string[string.startIndex..<colIdx]),
101-
pass: String(string[colIdx..<string.endIndex])
101+
pass: String(string[string.index(after: colIdx)..<string.endIndex])
102102
)
103103
}
104104
#endif // canImport(Foundation)

Sources/http/IncomingMessage.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,10 @@ open class IncomingMessage: ReadableByteStream, CustomStringConvertible {
274274
}
275275
}
276276

277-
/// The URI associated with the request as a plain string.
278-
/// Returns an empty string for responses.
277+
/**
278+
* The URI associated with the request as a plain string.
279+
* Returns an empty string for responses.
280+
*/
279281
@inlinable
280282
public var url : String {
281283
switch head {

Sources/http/Support/HTTPHeadersHolder.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,42 @@ public protocol HTTPMutableHeadersHolder: HTTPHeadersHolder {
1515
var headers : HTTPHeaders { get set }
1616
}
1717

18+
// MARK: - Express API
19+
20+
public extension HTTPHeadersHolder {
21+
22+
/**
23+
* Returns the value of a header, or nil if the header is empty.
24+
*
25+
* If there are multiple headers w/ the same name, their value is joined
26+
* by ", ", e.g.:
27+
* ```http
28+
* Accept: text/html
29+
* Accept: application/json
30+
* ```
31+
* will result in this:
32+
* ```swift
33+
* > req.get("accept")
34+
* "text/html, application/json
35+
* ```
36+
*/
37+
@inlinable
38+
func header(_ headerName: String) -> String? {
39+
let values = headers[headerName]
40+
guard !values.isEmpty else { return nil }
41+
return headers[headerName].joined(separator: ", ")
42+
}
43+
44+
/**
45+
* Aliased for ``header(_:)``.
46+
*/
47+
@inlinable
48+
func get(_ headerName: String) -> String? {
49+
return header(headerName)
50+
}
51+
}
52+
53+
1854
// MARK: - Node API
1955

2056
public extension HTTPHeadersHolder {

0 commit comments

Comments
 (0)