refactor: apply stashed bridge + CLI changes
This commit is contained in:
@@ -186,39 +186,37 @@ final class WebChatServer: @unchecked Sendable {
|
||||
over: connection)
|
||||
return
|
||||
}
|
||||
guard let data = try? Data(contentsOf: fileURL) else {
|
||||
webChatServerLogger.error("WebChatServer 404 missing \(fileURL.lastPathComponent, privacy: .public)")
|
||||
self.send(
|
||||
status: 404,
|
||||
mime: "text/plain",
|
||||
body: Data("Not Found".utf8),
|
||||
contentLength: "Not Found".utf8.count,
|
||||
includeBody: includeBody,
|
||||
over: connection)
|
||||
return
|
||||
}
|
||||
let mime = self.mimeType(forExtension: fileURL.pathExtension)
|
||||
self.send(
|
||||
status: 200,
|
||||
mime: mime,
|
||||
body: data,
|
||||
contentLength: data.count,
|
||||
includeBody: includeBody,
|
||||
over: connection)
|
||||
}
|
||||
guard let data = try? Data(contentsOf: fileURL) else {
|
||||
webChatServerLogger.error("WebChatServer 404 missing \(fileURL.lastPathComponent, privacy: .public)")
|
||||
self.send(
|
||||
status: 404,
|
||||
mime: "text/plain",
|
||||
body: Data("Not Found".utf8),
|
||||
includeBody: includeBody,
|
||||
over: connection)
|
||||
return
|
||||
}
|
||||
let mime = self.mimeType(forExtension: fileURL.pathExtension)
|
||||
self.send(
|
||||
status: 200,
|
||||
mime: mime,
|
||||
body: data,
|
||||
includeBody: includeBody,
|
||||
over: connection)
|
||||
}
|
||||
|
||||
private func send(
|
||||
status: Int,
|
||||
mime: String,
|
||||
body: Data,
|
||||
contentLength: Int,
|
||||
includeBody: Bool,
|
||||
over connection: NWConnection)
|
||||
{
|
||||
let headers = "HTTP/1.1 \(status) \(statusText(status))\r\n" +
|
||||
"Content-Length: \(contentLength)\r\n" +
|
||||
"Content-Type: \(mime)\r\n" +
|
||||
"Connection: close\r\n\r\n"
|
||||
private func send(
|
||||
status: Int,
|
||||
mime: String,
|
||||
body: Data,
|
||||
includeBody: Bool,
|
||||
over connection: NWConnection)
|
||||
{
|
||||
let contentLength = body.count
|
||||
let headers = "HTTP/1.1 \(status) \(statusText(status))\r\n" +
|
||||
"Content-Length: \(contentLength)\r\n" +
|
||||
"Content-Type: \(mime)\r\n" +
|
||||
"Connection: close\r\n\r\n"
|
||||
var response = Data(headers.utf8)
|
||||
if includeBody {
|
||||
response.append(body)
|
||||
|
||||
Reference in New Issue
Block a user