-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresponse.wren
More file actions
39 lines (32 loc) · 837 Bytes
/
Copy pathresponse.wren
File metadata and controls
39 lines (32 loc) · 837 Bytes
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
import "./status" for Status
class Response {
construct new(statusCode, messageBody) {
_statusCode = statusCode
_messageBody = messageBody
}
body() {
if (_messageBody) {
return _messageBody
} else {
return ""
}
}
// returns the size of the body in bytes plus 1 byte (the newline
// character which `System.print` appends)
bodySize() {
return (body().count + 1).toString
}
headers() {
return status + date + expires + server + type + length
}
write() {
System.print(headers())
System.print(body())
}
status { "HTTP/1.0 " + Status.new(_statusCode).print() }
date { "Date: \r\n" }
expires { "Expires: \r\n" }
server { "Server: wren-server\r\n" }
type { "Content-Type: text/plain\r\n" }
length { "Content-Length: " + bodySize() + "\r\n" }
}