Class TestServer
In: test/http_test_server.rb
Parent: Object

Methods

add_tests   dbg   new   shutdown   start  

Constants

SUCCESS_TEXT_0 = "success_0"
SUCCESS_TEXT_1 = "success_1"
SUCCESS_TEXT_2 = "success_2"
SUCCESS_TEXT_3 = "success_3"
SUCCESS_TEXT_4 = "success_4"
SUCCESS_TEXT_5 = "success_5"
SUCCESS_TEXT_6 = "success_6"
SUCCESS_TEXT_7 = "success_7"
SUCCESS_TEXT_8 = "success_8"
SUCCESS_TEXT_9 = "success_9"
POST_DATA = [0xbe, 0x00, 0x12, 0x23, 0x45, 0x67, 0x89, 0xAB].join

Public Class methods

[Source]

    # File test/http_test_server.rb, line 19
19:         def initialize
20:                 @server = HTTPServer.new(
21:                         :Port => 12345
22:                 )
23: 
24:                 add_tests
25:         end

Public Instance methods

[Source]

    # File test/http_test_server.rb, line 38
38:         def add_tests
39:                 # return a text
40:                 @server.mount_proc("/test1"){|req, res|
41:                         res.body=SUCCESS_TEXT_0
42:                 }
43:                 #return value of query param named "query"
44:                 @server.mount_proc("/test2"){|req, res|
45:                         res.body=req.query["query"]
46:                 }
47:                 
48:                 # return value of query param named "query2"
49:                 @server.mount_proc("/query_test2"){|req, res|
50:                         res.body=req.query["query2"]
51:                 }
52:                 
53:                 # return value of request header named "X-Special-Http-Header"
54:                 @server.mount_proc("/header_test"){|req, res|
55:                         res.body=req.header["x-special-http-header"][0]
56:                         res['x-special-response']=req.header["x-special-http-header"][0]
57:                 }
58:                 
59:                 # return value of request header named "X-Special-Http-Header"
60:                 @server.mount_proc("/post_data_test"){|req, res|
61:                         ctype = req.header['content-type'][0]
62:                         if "misc/test-data" == ctype 
63:                                 res.body=req.body
64:                         else
65:                                 res.body="failed, content-type: #{ctype}"
66:                         end  
67:                 }
68: 
69:                 @server.mount_proc("/basic_auth") {|req, res|
70:                         
71:                         auth = Base64.decode64(req.header['authorization'][0].split[1])
72:                         usr, pwd = auth.split(':')
73:                         if ('test'==usr && 'pwd'==pwd)
74:                                 res.body=SUCCESS_TEXT_1     
75:                         else
76:                                 res.status=403
77:                         end
78:                 }
79: 
80:                 1.upto(6) {|i|
81:                         @server.mount_proc("/redirect#{i}") { |req, res|
82:                                 res.status=301
83:                                 res.header['location']="http://127.0.0.1:12345/redirect#{i+1}"      
84:                         }
85:                 }
86:                 
87:                 @server.mount_proc("/redirect") { |req, res|
88:                         res.status=301
89:                         res.header['location']="http://127.0.0.1:12345/test1"        
90:                 }
91: 
92:                 @server.mount_proc("/redirect_special_header") { |req, res|
93:                         res.status=301
94:                         res.header['location']="http://127.0.0.1:12345/header_test"
95:                 }
96:         end

[Source]

    # File test/http_test_server.rb, line 35
35:         def dbg str 
36:                 puts "!!!!!!!!! #{str}"
37:         end

[Source]

    # File test/http_test_server.rb, line 31
31:         def shutdown
32:                 @server.shutdown
33:         end

[Source]

    # File test/http_test_server.rb, line 27
27:         def start
28:                 @server.start
29:         end

[Validate]