增强&优化&修复一些主要涉及HttpServer业务的使用#714
Closed
House-Men wants to merge 1 commit intoithewei:masterfrom
Closed
Conversation
73def20 to
c1901ce
Compare
support http handler chain return HTTP_STATUS_WANT_CLOSE support http server bind onAccept and onClose callback support http legal relative path request optimize http path safe check Performance and Process optimize http server path file cache map key fix hv_parse_url processing '#' and '?' order priority bug fix false positives '/..file' normal path bug add hv_normalize_path function to hbase.h fix defaultLargeFileHandler not support chinese path add windows hv::utf8_to_ansi and hv::ansi_to_utf8 function to hstring.h optimize some log level and msg desc
Owner
|
感谢你的贡献! |
Contributor
Author
|
@ithewei 好吧 看样子我要PR刷帖了 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
支持自定义 http 处理链 headerHandler
能够在内部一些默认处理之前最优先做业务处理,例如需要对请求头或Host域做检查,如果不合法可忽略hv内部的RecvBody,Expect100,Proxy,ProtocolUpgrade等等一系列的内置处理,也可提前做个性化的rewrite头部信息从而影响hv后续的一些默认处理行为。
支持 http 处理程序链返回 HTTP_STATUS_WANT_CLOSE
能够在各个处理链线程安全的通过返回此值要求无视Http头keep-alive强制关闭连接,甚至可选搭配处理链的回调中将ctx->writer->state = hv::HttpResponseWriter::SEND_END; 实现取消hv内部默认响应http状态包变为自定义响应非http报文或不响应任何数据,让非法访问无法探测外网端口的具体服务性质。
支持 http 服务器绑定 onAccept 和 onClose 回调
满足一些需要对HttpServer通讯层socket套接字hio做一些业务处理或计数器需求。
支持 http 合法相对路径请求
优化 http 请求路径安全检查性能和流程
优化 http 服务器相对路径文件缓存映射键
因为内部文件缓存map的key是文件路径,而未经规范化处理的路径格式存在对相同的文件形成无数种字符变化,易造成原本个位数的真实有效文件被外网恶意请求分配出无数个文件缓存造成内存影响,同时也避免了Windows相比Linux的路径兼容性严格程度不同导致的末尾反斜杠不应该访问成功的请求却能够open成功。
添加 hv_normalize_path 函数到 hbase.h
实用的文件路径规范化修剪处理函数解决上述路径相关问题的关键实现。
修复误报“/..file”正常文件路径 bug
解决某些文件确实前面几个点符号造成被误判为相对父路径从而终止了请求。
修复 hv_parse_url 处理 '#' 和 '?' 顺序优先级 bug
解决类似“/xxx/xxx.htm#xxx?xxxx”的顺序导致解析结果有错误。
修复 defaultLargeFileHandler 在Windows环境不支持中文
在 hstring.h 中添加 hv::utf8_to_ansi 和 hv::ansi_to_utf8 函数
因为这个内部的大文件处理是采用的HFile封装的标准库ANSI函数处理,而通常只有Windows环境的ANSI不是UTF8编码,所以为了改动幅度最小化并且避免引入iconv外部第三方编码转换库只好借助内置的窄宽字符转换先将浏览器请求的UTF8字符串转换到宽字符,在从宽字符转换到对应本地化编码的ANSI,虽然存在两次转换但大文件传输并不高频触发影响不大,为了方便后续Windows环境有这方面转换需要都整合到hstring.h中了。
优化部分日志级别和消息描述
某些日志内容完全一样不易区分而且没有携带ip,port,ssl具体错误这样的此类重要信息所以调整了下描述内容,还有些与Server处理强相关的fprintf(stderr)输出的错误会因外部高频请求造成频繁输出在shell便调整到hlog默认日志模块记录了。