-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathWOResponse.swift
More file actions
54 lines (41 loc) · 1.22 KB
/
WOResponse.swift
File metadata and controls
54 lines (41 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
// WOResponse.swift
// SwiftObjects
//
// Created by Helge Hess on 11.05.18.
// Copyright © 2018 ZeeZide. All rights reserved.
//
open class WOResponse : WOMessage, WOActionResults {
// TODO: enableStreaming() (implement in NIO subclass)
open var status = 200
public let request : WORequest?
public init(request: WORequest? = nil) {
self.request = request
super.init()
setHeader("text/html; charset=utf-8", for: "Content-Type")
}
open func generateResponse() throws -> WOResponse {
return self
}
open func disableClientCaching() {
// TODO: add expires header
// TODO: maybe add some etag which changes always?
// TODO: check whether those are correct
setHeader("no-cache", for: "Cache-Control")
setHeader("no-cache", for: "Pragma")
}
// MARK: - KVC
override open func value(forKey k: String) -> Any? {
switch k {
case "status": return status
case "request": return request
default: return super.value(forKey: k)
}
}
// MARK: - Description
override open func appendToDescription(_ ms: inout String) {
ms += " status=\(status)"
if let _ = request { ms += " has-rq" }
super.appendToDescription(&ms)
}
}