コード例 #1
0
 def test_set_output_header(self):
     request = HTTPServerRequest(method='GET', uri='/')
     exchange = HTTPExchange(request)
     actions = Actions(set_output_header=('Header-Name', 'header value'))
     actions.execute_output_actions(exchange)
     self.assertEqual(exchange.response.headers['Header-Name'],
                      'header value')
コード例 #2
0
 def test_del_output_header(self):
     headers = HTTPHeaders()
     headers.add("Header-Name", "header value1")
     request = HTTPServerRequest(method='GET', uri='/')
     exchange = HTTPExchange(request)
     exchange.response.headers = headers
     actions = Actions(del_output_header="Header-Name")
     actions.execute_output_actions(exchange)
     keys = list(exchange.response.headers.keys())
     self.assertEquals(len(keys), 0)
     actions = Actions(del_output_header="Header-Name2")
     actions.execute_output_actions(exchange)
コード例 #3
0
 def test_add_output_header(self):
     headers = HTTPHeaders()
     headers.add("Header-Name", "header value1")
     request = HTTPServerRequest(method='GET', uri='/')
     exchange = HTTPExchange(request)
     exchange.response.headers = headers
     actions = Actions(add_output_header=("Header-Name", "header value2"))
     actions.execute_output_actions(exchange)
     values = exchange.response.headers.get_list('Header-Name')
     self.assertEquals(len(values), 2)
     self.assertEquals(values[0], "header value1")
     self.assertEquals(values[1], "header value2")
コード例 #4
0
 def test_set_output_body(self):
     request = HTTPServerRequest(method='GET', uri='/')
     exchange = HTTPExchange(request)
     actions = Actions(set_output_body=b"foobar")
     actions.execute_output_actions(exchange)
     self.assertEqual(exchange.response.body, b"foobar")