Skip to content
This repository has been archived by the owner on May 26, 2024. It is now read-only.

Commit

Permalink
added more files
Browse files Browse the repository at this point in the history
  • Loading branch information
zaneenders committed Jan 5, 2024
1 parent 0f54e5e commit fb8d1cb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
30 changes: 26 additions & 4 deletions Sources/WebsiteBuilder/Server/HttpHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,16 @@ func httpResponseHead(

extension Server.HTTPHandler {

enum FileType {
case ico
case svg_xml
}
// Chopped up from HTTP1 Server Example
private func handleFile(
context: ChannelHandlerContext,
request: HTTPServerRequestPart,
_ filePath: String
_ filePath: String,
_ type: FileType
) {
self.buffer.clear()
switch request {
Expand All @@ -164,8 +169,14 @@ extension Server.HTTPHandler {
var response = httpResponseHead(request: request, status: .ok)
response.headers.add(
name: "Content-Length", value: "\(region.endIndex)")
response.headers.add(
name: "Content-Type", value: "image/x-icon")
switch type {
case .ico:
response.headers.add(
name: "Content-Type", value: "image/x-icon")
case .svg_xml:
response.headers.add(
name: "Content-Type", value: "image/svg+xml")
}
context.write(
self.wrapOutboundOut(.head(response)), promise: nil)
context.writeAndFlush(
Expand Down Expand Up @@ -199,10 +210,21 @@ extension Server.HTTPHandler {
}
switch reqPart {
case .head(let request):
// TODO how do we not manually add this routes
if request.uri == "/favicon.ico" {
self.handler = { c, r in
self.handleFile(
context: c, request: r, "Resources/favicon.ico"
context: c, request: r, "Resources/favicon.ico", .ico
)
}
self.handler!(context, reqPart)
return
}
if request.uri == "/github-mark.svg" {
self.handler = { c, r in
self.handleFile(
context: c, request: r, "Resources/github-mark.svg",
.svg_xml
)
}
self.handler!(context, reqPart)
Expand Down
1 change: 1 addition & 0 deletions Sources/WebsiteBuilder/WebPage.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
public protocol WebPage: HasURL, HasContent, HasSubPages {
// TODO maybe rename with an underscore so this is harder to overwrite?
var contents: String { get }
init() // Thing I will want to change this.
// So that things can be composed and you pass in one initialized tree
Expand Down

0 comments on commit fb8d1cb

Please sign in to comment.