BaseHTTPServer 中的一些问题

2016-03-08 13:56:09 +08:00
 cc7756789

https://hg.python.org/cpython/file/2.7/Lib/BaseHTTPServer.py

Line 310

self.raw_requestline = self.rfile.readline(65537)

这个 65537 是什么意思?

3111 次点击
所在节点    Python
7 条回复
glasslion
2016-03-08 14:09:38 +08:00
DuckJK
2016-03-08 14:25:47 +08:00
HTTP 1.1 协议中对 url 的长度是不受限制的,但是实际上对于服务端和浏览器来说一般是 4K 或者 8K
8K=8192 字节=65536Byte
self.raw_requestline = self.rfile.readline(65537)
if len(self.raw_requestline) > 65536:
self.requestline = ''
self.request_version = ''
self.command = ''
self.send_error(414)
return
下面 send_error(414),可以在最下面找到 414 表示的是 414: ('Request-URI Too Long', 'URI is too long.'),
然后我百度了下: URL,URN 是 URI 的子集
另外 readlines(size)表示这个: size -- This is the number of bytes to be read from the file
好像很接近 65537 的样子。。。。

上面讲的可能有错误,仅供参考。
knightdf
2016-03-08 14:33:21 +08:00
8K=8192 字节=65536Byte .........
DuckJK
2016-03-08 14:50:19 +08:00
@knightdf 我就知道有地方错了。。。
kimown
2016-03-08 15:27:50 +08:00
回复和问题无关,但也是 http 中关于 body 体的限制.
这是《 HTTP 权威指南》里分块编码的一句话:它由起始的 HTTP 响应首部块开始,随后就是一系列分块。每个分块包含一个长度值和该分块的数据。长度值是十六进制形式并将 CRLF 与数据分隔开。
不知道。
这里面的长度值也是 16 位的。
julyclyde
2016-03-08 23:09:43 +08:00
@kimown rfc2616 是这么写的:
The chunk-size field is a string of hex digits indicating the size of
the chunk. The chunked encoding is ended by any chunk whose size is
zero, foll
并没有说必须是 16 位
kimown
2016-03-09 09:14:09 +08:00
@julyclyde 感谢,受教了

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/261906

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX