Project updates from Template #1
@@ -5,6 +5,8 @@ public extension HTTPField.Name {
|
|||||||
static let permissionsPolicy = Self("Permissions-Policy")!
|
static let permissionsPolicy = Self("Permissions-Policy")!
|
||||||
/// The `Referrer-Policy` field name (not provided as a standard `HTTPField.Name`).
|
/// The `Referrer-Policy` field name (not provided as a standard `HTTPField.Name`).
|
||||||
static let referrerPolicy = Self("Referrer-Policy")!
|
static let referrerPolicy = Self("Referrer-Policy")!
|
||||||
|
/// The `X-Robots-Tag` field name (not provided as a standard `HTTPField.Name`).
|
||||||
|
static let robotsTag = Self("X-Robots-Tag")!
|
||||||
/// The `X-Frame-Options` field name (not provided as a standard `HTTPField.Name`).
|
/// The `X-Frame-Options` field name (not provided as a standard `HTTPField.Name`).
|
||||||
static let frameOptions = Self("X-Frame-Options")!
|
static let frameOptions = Self("X-Frame-Options")!
|
||||||
/// The `X-Forwarded-For` field name (not provided as a standard `HTTPField.Name`).
|
/// The `X-Forwarded-For` field name (not provided as a standard `HTTPField.Name`).
|
||||||
|
|||||||
@@ -116,6 +116,11 @@ private extension HealthController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Builds a JSON response carrying the given status and payload.
|
/// Builds a JSON response carrying the given status and payload.
|
||||||
|
///
|
||||||
|
/// Every response is marked `noindex`. The checks answer `200 OK` to anyone who asks and nothing on the site links to them, so they are
|
||||||
|
/// unlikely to be found — but `robots.txt` allows the whole site, and a path that leaks into a log, a monitor, or an inbound link is crawlable
|
||||||
|
/// on discovery. The header keeps them out of the index even once they are fetched, which a `Disallow` rule would not: that stops the crawl, not
|
||||||
|
/// the indexing, and publishes the paths to everyone reading the file.
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - status: the HTTP status of the response.
|
/// - status: the HTTP status of the response.
|
||||||
/// - payload: the JSON body of the response.
|
/// - payload: the JSON body of the response.
|
||||||
@@ -126,7 +131,10 @@ private extension HealthController {
|
|||||||
) -> Response {
|
) -> Response {
|
||||||
Response(
|
Response(
|
||||||
status: status,
|
status: status,
|
||||||
headers: [.contentType: "application/json"],
|
headers: [
|
||||||
|
.contentType: "application/json",
|
||||||
|
.robotsTag: "noindex",
|
||||||
|
],
|
||||||
body: .init(byteBuffer: .init(string: payload))
|
body: .init(byteBuffer: .init(string: payload))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import Hummingbird
|
import Hummingbird
|
||||||
import HummingbirdTesting
|
import HummingbirdTesting
|
||||||
|
import Infrastructure
|
||||||
import Logging
|
import Logging
|
||||||
import NIOCore
|
import NIOCore
|
||||||
import Persistence
|
import Persistence
|
||||||
@@ -29,6 +30,7 @@ struct HealthControllerTests {
|
|||||||
#expect(response.status == .ok)
|
#expect(response.status == .ok)
|
||||||
#expect(response.headers[.contentType] == "application/json")
|
#expect(response.headers[.contentType] == "application/json")
|
||||||
#expect(body == #"{"status":"ok"}"#)
|
#expect(body == #"{"status":"ok"}"#)
|
||||||
|
#expect(response.headers[.robotsTag] == "noindex")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,6 +56,7 @@ struct HealthControllerTests {
|
|||||||
#expect(response.status == .ok)
|
#expect(response.status == .ok)
|
||||||
#expect(response.headers[.contentType] == "application/json")
|
#expect(response.headers[.contentType] == "application/json")
|
||||||
#expect(body == #"{"status":"ready"}"#)
|
#expect(body == #"{"status":"ready"}"#)
|
||||||
|
#expect(response.headers[.robotsTag] == "noindex")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
@@ -99,6 +102,7 @@ struct HealthControllerTests {
|
|||||||
#expect(response.status == .serviceUnavailable)
|
#expect(response.status == .serviceUnavailable)
|
||||||
#expect(response.headers[.contentType] == "application/json")
|
#expect(response.headers[.contentType] == "application/json")
|
||||||
#expect(body == #"{"status":"unavailable"}"#)
|
#expect(body == #"{"status":"unavailable"}"#)
|
||||||
|
#expect(response.headers[.robotsTag] == "noindex")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
Reference in New Issue
Block a user