Skip to content

Commit d928e96

Browse files
committed
Update Application API.
Applications now return response bodies via Reader classes. The application must return a Reader if it wishes to have a response body in the request. If null is returned, no response will be sent.
1 parent 076b6d0 commit d928e96

File tree

2 files changed

+14
-35
lines changed

2 files changed

+14
-35
lines changed

examples/hello.ooc

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
use web, fastcgi
22

3+
import io/Reader
4+
import text/StringBuffer
35
import web/[Application]
46
import fastcgi/Server
57

68

79
HelloApplication: class extends Application {
8-
parseRequest: func {
10+
processRequest: func -> Reader {
911
"Request path: %s" format(request path) println()
1012
"Request method: %s" format(request method) println()
1113
"Request remote addr: %s port %d" format(request remoteAddress, request remotePort) println()
12-
}
13-
14-
sendHeaders: func(headers: HeaderMap) {
15-
headers["Content-type"] = "text/html"
16-
}
1714

18-
sendResponse: func(response: ResponseWriter) {
19-
response write("<html>"). write("<body>"). write("<h1>Hello!</h1>"). write("</body></html>")
15+
response sendHeader("Content-type", "text/html")
16+
out := BufferReader new()
17+
out buffer() append("<html><body><h1>Hello world from ooc!!!</h1></body></html>")
18+
return out
2019
}
2120
}
2221

web/Application.ooc

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import structs/HashMap
1+
import io/Reader
22

33

44
Request: abstract class {
@@ -11,35 +11,15 @@ Request: abstract class {
1111
getHeader: abstract func(name: String) -> String
1212
}
1313

14-
ResponseWriter: abstract class {
15-
write: abstract func(data: String) -> Int
16-
flush: abstract func
14+
Response: abstract class {
15+
sendStatus: abstract func(code: Int, message: String)
16+
sendHeader: abstract func(name: String, value: String)
1717
}
1818

19-
HeaderMap: class extends HashMap<String> {
20-
init: func ~headermap {
21-
init(1)
22-
}
23-
24-
init: func ~headermapWithCapacity (capacity: UInt) {
25-
T = String
26-
super(capacity)
27-
}
28-
}
29-
operator [] <T> (map: HeaderMap, key: String) -> T {
30-
map get(key)
31-
}
32-
33-
operator []= <T> (map: HeaderMap, key: String, value: T) {
34-
map put(key, value)
35-
}
36-
37-
38-
Application: class {
19+
Application: abstract class {
3920
request: Request
21+
response: Response
4022

41-
parseRequest: func {}
42-
sendHeaders: func(headers: HeaderMap) {}
43-
sendResponse: func(response: ResponseWriter) {}
23+
processRequest: abstract func -> Reader
4424
}
4525

0 commit comments

Comments
 (0)