def test_cannot_send_headers_twice(self): req = self.make_request('GET', '/') resp = StreamResponse(req) resp.send_headers() with self.assertRaises(RuntimeError): resp.send_headers()
def test_cannot_change_content_length_after_sending_headers(self): req = self.make_request('GET', '/') resp = StreamResponse(req) resp.send_headers() with self.assertRaises(RuntimeError): resp.content_length = 123 self.assertIsNone(resp.content_length)
def hello(request): resp = StreamResponse(request) name = request.match_info.get('name', 'Anonimous') answer = ('Hello, ' + name).encode('utf8') resp.content_length = len(answer) resp.send_headers() resp.write(answer) yield from resp.write_eof() return resp
def test_cannot_change_content_type_after_sending_headers(self): req = self.make_request('GET', '/') resp = StreamResponse(req) resp.content_type = 'text/plain' resp.send_headers() with self.assertRaises(RuntimeError): resp.content_type = 'text/html' self.assertEqual('text/plain', resp.content_type)