V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
cc7756789
V2EX  ›  Python

BaseHTTPServer 中的一些问题

  •  
  •   cc7756789 · 2016-03-08 13:56:09 +08:00 · 3042 次点击
    这是一个创建于 2977 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    Line 310

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

    这个 65537 是什么意思?

    7 条回复    2016-03-09 09:14:09 +08:00
    glasslion
        1
    glasslion  
       2016-03-08 14:09:38 +08:00   ❤️ 1
    DuckJK
        2
    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
        3
    knightdf  
       2016-03-08 14:33:21 +08:00
    8K=8192 字节=65536Byte .........
    DuckJK
        4
    DuckJK  
       2016-03-08 14:50:19 +08:00
    @knightdf 我就知道有地方错了。。。
    kimown
        5
    kimown  
       2016-03-08 15:27:50 +08:00
    回复和问题无关,但也是 http 中关于 body 体的限制.
    这是《 HTTP 权威指南》里分块编码的一句话:它由起始的 HTTP 响应首部块开始,随后就是一系列分块。每个分块包含一个长度值和该分块的数据。长度值是十六进制形式并将 CRLF 与数据分隔开。
    不知道。
    这里面的长度值也是 16 位的。
    julyclyde
        6
    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
        7
    kimown  
       2016-03-09 09:14:09 +08:00
    @julyclyde 感谢,受教了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   764 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 20:43 · PVG 04:43 · LAX 13:43 · JFK 16:43
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.