【网络编程】——Lighttpd 返回HTTP/1.1 417 Expectation Failed

最近在使用python 的 pcurl 发送 post 请求到服务端的时候【服务端使用的服务是Lighttpd】,发现只要 post 请求的数据超过 1024 之后,就会返回如下错误:

* Hostname was NOT found in DNS cache
*   Trying 10.8.2.54...
* Connected to 10.8.2.54 (10.8.2.54) port 9997 (#11)
> POST /rest/cm/changeconfig HTTP/1.1
User-Agent: PycURL/7.43.0 libcurl/7.35.0 OpenSSL/1.0.1f zlib/1.2.8 libidn/1.28 librtmp/2.3
Host: 10.8.2.54:9997
Accept: application/json
Authorization: Basic YXJyYXk6YWRtaW4=
Content-Length: 1025
Content-Type: application/x-www-form-urlencoded
Expect: 100-continue

< HTTP/1.1 417 Expectation Failed
< Content-Type: text/html
< Content-Length: 363
< Connection: close
< Date: Wed, 26 Apr 2017 17:34:58 GMT
* Server lighttpd/1.4.34 is not blacklisted
< Server: lighttpd/1.4.34
< 
* Closing connection 11

百思不得其解,post 的数据为 1024 的时候,可以正常使用,于是乎在客户端和服务端分别抓包看了一眼。10.8.2.68:客户端  10.8.2.54:服务端

从数据包可以看出,首先客户端和服务端三次握手成功之后,由于post数据超过了1024,超过了链路最大传输单元,需要分片。此时客户端发送一个发送一个请求, 包含一个Expect:100-continue, 询问Server使用愿意接受数据,客户端接收到Server返回的100-continue应答以后, 才把数据POST给Server。于是,这样就有了一个问题, 并不是所有的Server都会正确应答100-continue, 比如lighttpd, 就会返回417 “Expectation Failed”, 则会造成逻辑出错。

查询一下说是lighttpd v1.4.x不支持“Expect: 100-continue”HTTP头,解决的方法如下:

一:使用 Lighttpd 1.50

二:lighttpd 1.4.21或以上版本(即最新的realease版本),只要在lighttpd配置文件中加入server.reject-expect-100-with-417="disable"即可

 

posted @ 2017-04-26 19:06  net小伙  阅读(1272)  评论(0编辑  收藏  举报