Implementation of InputBuffer which provides HTTP request header parsing as well as transfer decoding
socket能获得客户端发来的http协议,tomcat需要对http协议(传输的是byte流)进行解析,例如获得http的method,protocol,URI等信息.
既然是对byte流进行处理,tomcat封装了InternalInputBuffer。
Java代码
public
class
InternalInputBuffer
extends
AbstractInputBuffer
public class InternalInputBuffer extends AbstractInputBuffer
核心函数为
public boolean parseRequestLine(boolean useAvailableDataOnly)
public boolean parseHeader()
有多个header,循环处理
Java代码
public
boolean
parseHeaders()
throws
IOException {
while
(parseHeader()) {
}
parsingHeader = false
;
end = pos;
return
true
;
}
public boolean parseHeaders()
throws IOException {
while (parseHeader()) {
}
parsingHeader = false;
end = pos;
return true;
}
一个简单例子:
改写分析9中的例子