Home > Mobile >  what is meximum length of each line in each Http request and headers that can come which should be v
what is meximum length of each line in each Http request and headers that can come which should be v

Time:10-12

I have this http header that came to my C server include include request and headers. I like to know

"GET / HTTP/1.1\r\n" /
"Host: localhost:5000\r\n" /
"User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:93.0) Gecko/20100101 Firefox/93.0\r\n" /
"Accept: text/html,application/xhtml xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8\r\n" /
"Accept-Language: en-US,en;q=0.5\r\n" /
"Accept-Encoding: gzip, deflate\r\n" /
"Connection: keep-alive\r\n" /
"Upgrade-Insecure-Requests: 1\r\n" /
"Sec-Fetch-Dest: document\r\n" /
"Sec-Fetch-Mode: navigate\r\n" /
"Sec-Fetch-Site: none\r\n" /
"Sec-Fetch-User: ?1\r\n" /

what is the max size of each line until '\n' according to HTTP protocol which should be valid

"GET / HTTP/1.1\r\n" /

,

"Host: localhost:5000\r\n" /

,

 "User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:93.0) Gecko/20100101 Firefox/93.0\r\n" /

,

, , , ,

 "Sec-Fetch-User: ?1"

so I can try parsing it easily.

CodePudding user response:

The short answer is that there is no such restriction. The web server may have a limit on the total size of the HTTP request headers it will accept.

  • Apache : 8K
  • IIS : 8K - 16K
  • nginx : 4K - 8K
  • Tomcat : 8K - 16K

You could test the limit of your server by sending requests with junk headers and checking the response status code. A 400, 413 or 431 response would be an indication that you reached the limit.

CodePudding user response:

There seems to be no protocol-level limit. Existing limits are implementation specific. Which means that you parse as much as you can and when you can't anymore you respond 431 Request Header Fields Too Large

Quote:

431 can be used when the total size of request headers is too large, or when a single header field is too large
  •  Tags:  
  • c
  • Related