HTTP/1.x协议的具体实现。实现HTTPConnection接口。
16.1 构造函数
定义:
def __init__(self, stream, is_client, params=None, context=None):
参数:
stream:IOStream,输入输出流,用户读取或者写入数据。
is_client:代表是客户端连接还是服务端连接;
params:HTTP1ConnectionParameters实例。
context:可以通过connection.context访问得到。
这个构造函数里,就是对属性的初始化赋值。
主要的函数包括以下:
16.2 write_headers
写HTTP 头部
定义:
def write_headers(self, start_line, headers, chunk=None, callback=None):
参数:
start_line:开始行,RequestStartLine或者ResponseStartLine.
headers:就是HTTPHeaders实例。
chunk:可选参数,数据的第一个块,如果不传递时,设置成None
callback:回调函数,当写头部完成后调用。
返回值:
如果没有设置callback,则返回Future。
16.3 write
写body内数据。
定义:
def write(self, chunk, callback=None):
参数:
chunk:要写入的数据块
callback:回调函数。当写入完成后调用
返回值:
如果没有设置callback,则返回Future。
16.4 finish
当最后一个body数据块写入完毕之后调用