Skip to content

Commit 0ab0bbb

Browse files
committed
add more og tags, and also return 405 for HEAD requests
1 parent e523952 commit 0ab0bbb

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

Sources/HTTPServer/HTTP.ServerLoop.swift

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -311,23 +311,26 @@ extension HTTP.ServerLoop
311311
{
312312
cop.reset()
313313

314-
guard
315-
case .GET = h1.method
316-
else
314+
switch h1.method
317315
{
318-
return .resource("Method requires HTTP/2", status: 505)
319-
}
316+
case .HEAD:
317+
return .resource("Method not allowed", status: 405)
320318

321-
if let request:IntegralRequest = .init(get: h1.uri,
322-
headers: h1.headers,
323-
address: address,
324-
service: service)
325-
{
326-
return try await cop.pause { try await self.response(for: request) }
327-
}
328-
else
329-
{
330-
return .resource("Malformed request", status: 400)
319+
case .GET:
320+
if let request:IntegralRequest = .init(get: h1.uri,
321+
headers: h1.headers,
322+
address: address,
323+
service: service)
324+
{
325+
return try await cop.pause { try await self.response(for: request) }
326+
}
327+
else
328+
{
329+
return .resource("Malformed request", status: 400)
330+
}
331+
332+
default:
333+
return .resource("Method requires HTTP/2", status: 505)
331334
}
332335
}
333336
}
@@ -456,6 +459,9 @@ extension HTTP.ServerLoop
456459

457460
switch method
458461
{
462+
case "HEAD":
463+
return .resource("Method not allowed", status: 405)
464+
459465
case "GET":
460466
if let request:IntegralRequest = .init(get: path,
461467
headers: headers,

Sources/SwiftinitRender/Pages/Swiftinit.RenderablePage.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ extension Swiftinit.RenderablePage
8383
$0.href = "https://swiftinit.org\(canonical)"
8484
$0.rel = .canonical
8585
}
86+
$0[.meta]
87+
{
88+
$0.property = .og_url
89+
$0.content = "https://swiftinit.org\(canonical)"
90+
}
8691
}
8792
// Inlining this saves the client a round-trip to the google fonts API.
8893
// It is only about 1.87 KB, which is less than 5 percent of the total
@@ -117,6 +122,8 @@ extension Swiftinit.RenderablePage
117122

118123
$0[.meta] { $0.property = .og_title ; $0.content = self.title }
119124
$0[.meta] { $0.property = .og_image ; $0.content = favicon }
125+
$0[.meta] { $0.property = .og_type ; $0.content = "website" }
126+
$0[.meta] { $0.property = .og_site_name ; $0.content = "Swiftinit" }
120127

121128
self.head(augmenting: &$0, format: format)
122129
}

0 commit comments

Comments
 (0)