thttpd源码分析-----http协议头部检测

在源码中,用于http 头部检测的是 httpd_got_request 函数

该函数并没有检测头部的内容,只是检测头部的格式而已,最明显的格式检测就是 \r\n ,空格,tab符 ,即http协议中,头部的每一行都用 \r\n 结尾,在行中,每一词用空格或tab符分开 ,说明更简单一些,就是检查请求行是不是有三个words,头部结束是不是以空行结束 。仅此而已

下面是用的几种状态来检测格式是否合法的

/* Checks hc->read_buf to see whether a complete request has been read so far;
 ** either the first line has two words (an HTTP/0.9 request), or the first
 ** line has three words and there's a blank line present.
 **
 ** hc->read_idx is how much has been read in; hc->checked_idx is how much we
 ** have checked so far; and hc->checked_state is the current state of the
 ** finite state machine.
 */
int httpd_got_request(httpd_conn* hc) {
	char c;

	for (; hc->checked_idx < hc->read_idx; ++hc->checked_idx) {
		c = hc->read_buf[hc->checked_idx];
		switch (hc->checked_state) {
		cas
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值