File tree Expand file tree Collapse file tree 2 files changed +14
-35
lines changed Expand file tree Collapse file tree 2 files changed +14
-35
lines changed Original file line number Diff line number Diff line change 1
1
use web, fastcgi
2
2
3
+ import io/Reader
4
+ import text/StringBuffer
3
5
import web/[Application]
4
6
import fastcgi/Server
5
7
6
8
7
9
HelloApplication : class extends Application {
8
- parseRequest : func {
10
+ processRequest : func -> Reader {
9
11
"Request path: %s" format (request path) println ()
10
12
"Request method: %s" format (request method) println ()
11
13
"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
- }
17
14
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
20
19
}
21
20
}
22
21
Original file line number Diff line number Diff line change 1
- import structs/HashMap
1
+ import io/Reader
2
2
3
3
4
4
Request : abstract class {
@@ -11,35 +11,15 @@ Request: abstract class {
11
11
getHeader : abstract func (name : String ) -> String
12
12
}
13
13
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 )
17
17
}
18
18
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 {
39
20
request : Request
21
+ response : Response
40
22
41
- parseRequest : func {}
42
- sendHeaders : func (headers : HeaderMap ) {}
43
- sendResponse : func (response : ResponseWriter ) {}
23
+ processRequest : abstract func -> Reader
44
24
}
45
25
You can’t perform that action at this time.
0 commit comments