mirror of
https://github.com/apple/swift-nio
synced 2026-11-28 05:14:23 +00:00
Accept dictionary literals for HTTPHeaders (#824)
### Motivation:
A convenience/shorthand for developers.
### Modifications:
Add conformance to ExpressibleByDictionaryLiteral along with implementation.
### Result:
The following is would then be legal in Vapor:
```
return HTTPResponse(status: .ok, headers: ["Content-Type": "text/html"],
body: "<table border=1><tr><td><i>Hello</i>, plugin!")
```
This commit is contained in:
1 parent
30446eea52
commit
f84b5b8087
3 files changed
+41
-1
No files matched your search
@@ -430,7 +430,7 @@ private extension UInt8 {
|
||||
/// field when needed. It also supports recomposing headers to a maximally joined
|
||||
/// or split representation, such that header fields that are able to be repeated
|
||||
/// can be represented appropriately.
|
||||
public struct HTTPHeaders: CustomStringConvertible {
|
||||
public struct HTTPHeaders: CustomStringConvertible, ExpressibleByDictionaryLiteral {
|
||||
|
||||
private final class _Storage {
|
||||
var buffer: ByteBuffer
|
||||
@@ -556,6 +556,14 @@ public struct HTTPHeaders: CustomStringConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
/// Construct a `HTTPHeaders` structure.
|
||||
///
|
||||
/// - parameters
|
||||
/// - elements: name, value pairs provided by a dictionary literal.
|
||||
public init(dictionaryLiteral elements: (String, String)...) {
|
||||
self.init(elements)
|
||||
}
|
||||
|
||||
private func isConnectionHeader(_ header: HTTPHeaderIndex) -> Bool {
|
||||
return self.buffer.equalCaseInsensitiveASCII(view: "connection".utf8, at: header)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user