コード例 #1
0
ファイル: test_protocol.py プロジェクト: fireswood/netlib
def test_expected_http_body_size():
    # gibber in the content-length field
    headers = Headers(content_length="foo")
    assert HTTP1Protocol.expected_http_body_size(headers, False, "GET", 200) is None
    # negative number in the content-length field
    headers = Headers(content_length="-7")
    assert HTTP1Protocol.expected_http_body_size(headers, False, "GET", 200) is None
    # explicit length
    headers = Headers(content_length="5")
    assert HTTP1Protocol.expected_http_body_size(headers, False, "GET", 200) == 5
    # no length
    headers = Headers()
    assert HTTP1Protocol.expected_http_body_size(headers, False, "GET", 200) == -1
    # no length request
    headers = Headers()
    assert HTTP1Protocol.expected_http_body_size(headers, True, "GET", None) == 0
コード例 #2
0
def test_expected_http_body_size():
    # gibber in the content-length field
    h = odict.ODictCaseless()
    h["content-length"] = ["foo"]
    assert HTTP1Protocol.expected_http_body_size(h, False, "GET", 200) is None
    # negative number in the content-length field
    h = odict.ODictCaseless()
    h["content-length"] = ["-7"]
    assert HTTP1Protocol.expected_http_body_size(h, False, "GET", 200) is None
    # explicit length
    h = odict.ODictCaseless()
    h["content-length"] = ["5"]
    assert HTTP1Protocol.expected_http_body_size(h, False, "GET", 200) == 5
    # no length
    h = odict.ODictCaseless()
    assert HTTP1Protocol.expected_http_body_size(h, False, "GET", 200) == -1
    # no length request
    h = odict.ODictCaseless()
    assert HTTP1Protocol.expected_http_body_size(h, True, "GET", None) == 0