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
  
55
  
56
  
57
  
58
  
59
  
60
  
61
  
62
  
63
  
64
  
65
  
66
  
67
  
68
  
69
  
70
  
71
  
72
  
73
  
74
  
75
  
START_MARKER 
 
define(setup_request_test,[[ 
  test_do( add_constant("R", Protocols.HTTP.Server.Request()) ) 
  test_do([[ 
  class FD { 
    inherit Stdio.FakeFile; 
    void add(string s) { 
      read_cb(0, s); 
    } 
  }; 
  add_constant("FD",FD("")); 
  ]]) 
  test_do( R->attach_fd(FD, 0, lambda(object x){} ); ) 
]]) 
 
define(clear_request_test,[[ 
  test_do( add_constant("R") ) 
  test_do( add_constant("FD") ) 
]]) 
 
setup_request_test() 
 
test_do( FD->add("GET /foo/bar+%20/zuul.html?ha=bla&esp=an&ha=xxor ") ) 
test_do( FD->add("HTTP/1.01\r") ) 
test_do( FD->add("\n") ) 
test_do( FD->add("Content-Length: 5\r\n") ) 
test_do( FD->add("Content-Length: 5\r\n") ) 
test_do( FD->add("Cookie:    A=a ; B=b;C=x\r\n") ) 
test_do( FD->add("Cookie: D=d;C=c\r\n") ) 
test_do( FD->add("User-Agent: testsuite.in\r\n") ) 
test_do( FD->add("\r\nH") ) 
 
dnl parse_request and parse_variables called. 
 
test_eq( R->request_raw, "GET /foo/bar+%20/zuul.html?ha=bla&esp=an&ha=xxor HTTP/1.01") ) 
test_eq( R->request_type, "GET" ) 
test_eq( R->protocol, "HTTP/1.1" ) 
test_eq( R->full_query, "/foo/bar+%20/zuul.html?ha=bla&esp=an&ha=xxor" ) 
test_eq( R->query, "ha=bla&esp=an&ha=xxor" ) 
test_eq( R->not_query, "/foo/bar+%20/zuul.html" ) 
 
test_equal( R->variables, ([ "esp":"an", "ha":({"bla","xxor"}) ]) ) 
test_eq( R->request_headers["content-length"], "5" ) 
test_eq( sizeof(R->request_headers), 3 ); 
 
test_do( FD->add("ELL") ) 
test_do( FD->add("OMG") ) 
 
dnl finalized called. 
 
test_eq( R->body_raw, "HELLO" ) 
test_equal( R->cookies, ([ "A":"a", "B":"b", "C":"c", "D":"d" ]) ) 
test_equal( R->misc, ([]) ) 
 
clear_request_test() 
 
dnl FIXME: Test transfer encoding chunked 
dnl FIXME: Test multipart/formdata 
 
setup_request_test() 
 
test_do( add_constant("req", "POST / HTTP/1.1\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; X11; Linux i686; en) Opera 9.00\r\nHost: localhost:8080\r\nAccept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1\r\nAccept-Language: en\r\nAccept-Encoding: deflate, gzip, x-gzip, identity, *;q=0\r\nReferer: http://localhost:8086/\r\nCookie: show_wurfl_state=65; I=78d69acdb6caee5d6b720b8ae37a387b3db9e10a46feee12a6e1717989f9b3c1; device_state=64\r\nCookie2: $Version=1\r\nContent-Length: 7\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\na=b&c=d") ) 
test_do( FD->add(req) ) 
 
test_equal( R->variables, ([ "a":"b", "c":"d" ]) ) 
test_eq( R->raw, req ) 
 
test_do( add_constant("req") ) 
clear_request_test() 
 
 
END_MARKER