-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
parser->FeedRecvData解析http头如果遇到错误,会直接hio_close,但仍返回code200 #666
Comments
解析出错的情况下,就会直接close,为什么还会返回响应? |
我的意思是解析出错了关闭连接没有问题,但应该告诉客户端BAD_REQUEST而不是OK。 |
使用libhv的httpclient代码如下:
|
问题已经确认,httpclient使用了HttpResponse类,这个类的Init方法status_code默认是HTTP_STATUS_OK,而httpclient初始化后直到服务器返回状态码才会更新,如果服务器直接关闭连接则httpclient类不会更新这个值,并且没有处理error的情况,导致http_client_exec即没返回error码,状态也是200 |
我在herr.h中增加了一个名为F(-1022, SERVERCLOSED, "server closed") 的定义。然后在http_client_exec函数中初始化response指针时,强行设置了status_code为110(随便定义的)状态。然后在客户关闭返回时判断没有其它错误而状态码仍是110时判定服务器意外关闭了连接,返回ERROR_SERVERCLOSED,问题解决。作者应该有更好的方法。 |
比如发起请求的url参数中含有未编码的中文字符时等parser错误的情况时,返回的状态码仍是200,但连接已被关闭。
The text was updated successfully, but these errors were encountered: