URL length limit in HTTP

Source: Internet
Author: User
Tags nginx server

As a result of the previous Web project, to use Get method to get data, but the results are often error, after careful investigation to find that the original URL length exceeded the limit, by shortening the URL and send multiple requests to solve the problem, and then on the Internet to check some information, found that the problem or hidden inside the mystery, More complex than you think.

First of all, in fact the HTTP 1.1 protocol to the length of the URL is unrestricted, the original protocol:

        the HTTP protocol does not place any a prior I limit on the length of a URI. Servers must is able to handle the URI of any resource they serve, and should is able to handle URIs of unbounded len Gth if they provide get-based forms that could generate such URIs. A server should return 414 (Request-uri Too Long) status if a URI is longer than the server can handle (see section 10.4.1 5).

Note:servers ought to being cautious about depending on URI lengths above 255 bytes, because some older client or proxyimple Mentations might not properly support these lengths.

Translation:

     http The protocol does not allow the length of the uri to be limited beforehand, and the server must be able to handle any uri for which they provide resources, And should be able to handle an infinite length of uris , this invalid length url may be on the client based on the Span style= ";p adding:0px" is generated when a request is >get . If the server cannot handle too long uri , the server should return 414 Status code (this status code represents the Span style= ";p adding:0px" >request-uri is too long).

Note : servers should be cautious when relying on URIs that are larger than 255 bytes, because some old customer or proxy implementations may not support these lengths.

See 3.2.1 in the Agreement

Although the protocol does not explicitly limit the length of the URL, but in the real implementation, the length of the URL is still limited, one is the server-side restrictions, and the other is the browser-side restrictions.

One, server-side

On the server side, mainly Apache,jboss and nginx, I found on the Internet adjustment method can participate in the following: about the HTTP request URL length and the request message body length research (a) (server side)

1.1 Nginx

Since the main use of Nginx in the project now, so emphasize its setting parameters:large_client_header_buffers

This parameter restricts the size of the maximum buffer allocated when the Nginx server accepts the header information requested by the client, which is the maximum size of the header information that the Nginx server accepts for one client request at a time. This header includes not only the request-line, but also the general information header, the request header field, and the length sum of the response header fields. This also limits the length of the URL to a considerable extent.

default limits for Nginx servers is 4K or 8K, which is based on the hardware configuration of the server, generally for the size of the memory page, the majority of the current is 4K, that is, 4096 bytes.

1.2 Nodejs

This is mainly for NODEJS programmers, if you do not do related development can directly ignore this section.

Nodejs HTTP service, set the URL length limit and headers size or relatively flexible, I simply implement the control program, where _limit is the URL length of the controller

Var http = require (' http ');var _limit = 40;var app =  Http.createserver (function (req,res) {  console.log (' Hello world ');   var potocol  =  ' http:\/\/';  var host = req.headers.host;  var url  = req.url;    var code = 200;  var allurl  =  potocol + host + url;  console.log (Allurl);   var len =  allurl.length;  if (len > _limit) {    var code =  414;    res.writehead (code, {});     res.end ();   }   else{    var body = {' name ': ' Jifeng '};     Res.writehead (code, {});     res.end (Json.stringify (body));   }); App.listen ( 1987,function () {  coNsole.log (' server listen on 1987 ');   }); 

Note: The limit in Connect has a module that implements similar functions,

Second, the Tour terminal

There are a variety of browser types, and the length limit for URLs is different, as follows:

These data are mainly through the online data search, the author has not personally verified. But there are limitations are indisputable facts, everyone in the development of special attention.

URL length limit in HTTP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.