最新消息:

HTTP 414返回码错误

Linux ipcpu 7645浏览

HTTP 414返回码错误.md

一、引入


在实际业务中,发生了多次HTTP返回码为414的情况。这种返回码还是比较罕见的。

经过排查,发现开发在前端对request URI进行了拼接,拼接完成以后,request URI长度达到了8k,因此触发了CDN链路上的某层限制,报出了414错误。

二、HTTP 414 含义

根据协议规范,响应码 414 URI Too Long 表示客户端所请求的 URI 超过了服务器允许的范围。

三、HTTP request的大小限制

对于一个HTTP request请求可以分为URI,HEADER,Body三个部分。

3.1 URI

HTTP协议中没有明确限制URI长度,但是浏览器和WEB服务器一般都会有限制。

浏览器限制

IE浏览器对URL的长度现限制为2048字节。
360极速浏览器对URL的长度限制为2118字节。
Firefox(Browser)对URL的长度限制为65536字节。
Safari(Browser)对URL的长度限制为80000字节。
Opera(Browser)对URL的长度限制为190000字节。
Google(chrome)对URL的长度限制为8182字节。

WEB服务器限制
以Nginx为例,在Nginx中,参数

large_client_header_buffers number size; 
默认值:large_client_header_buffers 4 8k;

用来控制request的URI长度和header大小。

当request的URI长度超过size值时报414错误,当request的header超过size值时报400错误。

Sets the maximum number and size of buffers used for reading large client request header. A request line cannot exceed the size of one buffer, or the 414 (Request-URI Too Large) error is returned to the client. A request header field cannot exceed the size of one buffer as well, or the 400 (Bad Request) error is returned to the client. Buffers are allocated only on demand. By default, the buffer size is equal to 8K bytes. If after the end of request processing a connection is transitioned into the keep-alive state, these buffers are released.

3.2 Header

HTTP Header中包含Accept、Cookie、UA等信息,如下

其中cookie大小限制可以查询相关文章。

浏览器限制
这个一直没有找到相关数据,应该足够用了。

WEB服务器限制
和上面一样large_client_header_buffers 这个参数也限制了Header的大小,如果超过回报400错误。

3.3 Body

body体一般用于文件上传,浏览器上没有限制,只需要关注服务器端限制即可,例如nginx的client_max_body_size。

参考资料

http://djt.qq.com/article/view/1047
http://nginx.org/en/docs/http/ngx_http_core_module.html#large_client_header_buffers
https://www.cnblogs.com/yjf512/archive/2013/03/29/2988296.html

转载请注明:IPCPU-网络之路 » HTTP 414返回码错误