buggy stringlengths 35 5.03k | fixed stringlengths 46 62.5k |
|---|---|
def __len__(self):
def received(self, data):
"See IStreamConsumer"
rm = self.remain
if rm < 1:
self.completed = True # Avoid any chance of spinning
return 0
datalen = len(data)
if rm <= datalen:
self.buf.append(data[:rm])
self.... | def __len__(self):
def received(self, data):
"See IStreamConsumer"
rm = self.remain
if rm < 1:
self.completed = True # Avoid any chance of spinning
return 0
datalen = len(data)
if rm <= datalen:
self.buf.append(data[:rm])
se... |
def getbuf(self):
class ChunkedReceiver(object):
chunk_remainder = 0
control_line = b""
all_chunks_received = False
trailer = b""
completed = False | def getbuf(self):
class ChunkedReceiver(object):
chunk_remainder = 0
validate_chunk_end = False
control_line = b""
chunk_end = b""
all_chunks_received = False
trailer = b""
completed = False |
def __len__(self):
def received(self, s):
# Returns the number of bytes consumed.
if self.completed:
return 0
orig_size = len(s)
while s:
rm = self.chunk_remainder
if rm > 0:
# Receive the remainder of a chunk.
to_w... | def __len__(self):
def received(self, s):
# Returns the number of bytes consumed.
if self.completed:
return 0
orig_size = len(s)
while s:
rm = self.chunk_remainder
if rm > 0:
# Receive the remainder of a chunk.
t... |
def received(self, s):
except ValueError: # garbage in input
self.error = BadRequest("garbage in chunked encoding input")
sz = 0
if sz > 0:
# Start a new chunk.
... | def received(self, s):
except ValueError: # garbage in input
self.error = BadRequest("garbage in chunked encoding input")
sz = 0
if sz > 0:
# Start a new chunk.
... |
def received(self, s):
else:
# Receive the trailer.
trailer = self.trailer + s
if trailer.startswith(b"\r\n"):
# No trailer.
self.completed = True
return orig_size - (len(trailer) - 2)
... | def received(self, s):
else:
# Receive the trailer.
trailer = self.trailer + s
if trailer.startswith(b"\r\n"):
# No trailer.
self.completed = True
return orig_size - (len(trailer) - 2)
... |
def received(self, s):
# Finished the trailer.
self.completed = True
self.trailer = trailer[:pos]
return orig_size - (len(trailer) - pos)
return orig_size
def getfile(self): | def received(self, s):
# Finished the trailer.
self.completed = True
self.trailer = trailer[:pos]
return orig_size - (len(trailer) - pos)
return orig_size
def getfile(self): |
def execute(self):
status, headers, body = e.to_response()
self.status = status
self.response_headers.extend(headers)
if self.version == "1.1":
connection = self.request.headers.get("CONNECTION", "").lower()
if connection == "close":
self.response_... | def execute(self):
status, headers, body = e.to_response()
self.status = status
self.response_headers.extend(headers)
# We need to explicitly tell the remote client we are closing the
# connection, because self.close_on_finish is set, and we are going to
# slam the door i... |
def test_del_channel(self):
def test_received(self):
inst, sock, map = self._makeOneWithMap()
inst.server = DummyServer()
inst.received(b"GET / HTTP/1.1\n\n")
self.assertEqual(inst.server.tasks, [inst])
self.assertTrue(inst.requests)
| def test_del_channel(self):
def test_received(self):
inst, sock, map = self._makeOneWithMap()
inst.server = DummyServer()
inst.received(b"GET / HTTP/1.1\r\n\r\n")
self.assertEqual(inst.server.tasks, [inst])
self.assertTrue(inst.requests)
|
def test_received_preq_not_completed(self):
inst.request = preq
preq.completed = False
preq.empty = True
inst.received(b"GET / HTTP/1.1\n\n")
self.assertEqual(inst.requests, ())
self.assertEqual(inst.server.tasks, [])
| def test_received_preq_not_completed(self):
inst.request = preq
preq.completed = False
preq.empty = True
inst.received(b"GET / HTTP/1.1\r\n\r\n")
self.assertEqual(inst.requests, ())
self.assertEqual(inst.server.tasks, [])
|
def test_received_preq_completed_empty(self):
inst.request = preq
preq.completed = True
preq.empty = True
inst.received(b"GET / HTTP/1.1\n\n")
self.assertEqual(inst.request, None)
self.assertEqual(inst.server.tasks, [])
| def test_received_preq_completed_empty(self):
inst.request = preq
preq.completed = True
preq.empty = True
inst.received(b"GET / HTTP/1.1\r\n\r\n")
self.assertEqual(inst.request, None)
self.assertEqual(inst.server.tasks, [])
|
def test_received_preq_error(self):
inst.request = preq
preq.completed = True
preq.error = True
inst.received(b"GET / HTTP/1.1\n\n")
self.assertEqual(inst.request, None)
self.assertEqual(len(inst.server.tasks), 1)
self.assertTrue(inst.requests) | def test_received_preq_error(self):
inst.request = preq
preq.completed = True
preq.error = True
inst.received(b"GET / HTTP/1.1\r\n\r\n")
self.assertEqual(inst.request, None)
self.assertEqual(len(inst.server.tasks), 1)
self.assertTrue(inst.requests) |
def test_received_preq_completed_connection_close(self):
preq.completed = True
preq.empty = True
preq.connection_close = True
inst.received(b"GET / HTTP/1.1\n\n" + b"a" * 50000)
self.assertEqual(inst.request, None)
self.assertEqual(inst.server.tasks, [])
def test_rec... | def test_received_preq_completed_connection_close(self):
preq.completed = True
preq.empty = True
preq.connection_close = True
inst.received(b"GET / HTTP/1.1\r\n\r\n" + b"a" * 50000)
self.assertEqual(inst.request, None)
self.assertEqual(inst.server.tasks, [])
def test... |
def test_received_headers_finished_expect_continue_false(self):
preq.completed = False
preq.empty = False
preq.retval = 1
inst.received(b"GET / HTTP/1.1\n\n")
self.assertEqual(inst.request, preq)
self.assertEqual(inst.server.tasks, [])
self.assertEqual(inst.outbuf... | def test_received_headers_finished_expect_continue_false(self):
preq.completed = False
preq.empty = False
preq.retval = 1
inst.received(b"GET / HTTP/1.1\r\n\r\n")
self.assertEqual(inst.request, preq)
self.assertEqual(inst.server.tasks, [])
self.assertEqual(inst.ou... |
def test_received_headers_finished_expect_continue_true(self):
preq.headers_finished = True
preq.completed = False
preq.empty = False
inst.received(b"GET / HTTP/1.1\n\n")
self.assertEqual(inst.request, preq)
self.assertEqual(inst.server.tasks, [])
self.assertEqual... | def test_received_headers_finished_expect_continue_true(self):
preq.headers_finished = True
preq.completed = False
preq.empty = False
inst.received(b"GET / HTTP/1.1\r\n\r\n")
self.assertEqual(inst.request, preq)
self.assertEqual(inst.server.tasks, [])
self.assertE... |
def test_received_headers_finished_expect_continue_true_sent_true(self):
preq.completed = False
preq.empty = False
inst.sent_continue = True
inst.received(b"GET / HTTP/1.1\n\n")
self.assertEqual(inst.request, preq)
self.assertEqual(inst.server.tasks, [])
self.asse... | def test_received_headers_finished_expect_continue_true_sent_true(self):
preq.completed = False
preq.empty = False
inst.sent_continue = True
inst.received(b"GET / HTTP/1.1\r\n\r\n")
self.assertEqual(inst.request, preq)
self.assertEqual(inst.server.tasks, [])
self.... |
def _read_echo(self, fp):
return line, headers, echo.parse_response(body)
def test_date_and_server(self):
to_send = "GET / HTTP/1.0\n" "Content-Length: 0\n\n"
to_send = tobytes(to_send)
self.connect()
self.sock.send(to_send) | def _read_echo(self, fp):
return line, headers, echo.parse_response(body)
def test_date_and_server(self):
to_send = "GET / HTTP/1.0\r\nContent-Length: 0\r\n\r\n"
to_send = tobytes(to_send)
self.connect()
self.sock.send(to_send) |
def test_date_and_server(self):
def test_bad_host_header(self):
# https://corte.si/posts/code/pathod/pythonservers/index.html
to_send = "GET / HTTP/1.0\n" " Host: 0\n\n"
to_send = tobytes(to_send)
self.connect()
self.sock.send(to_send) | def test_date_and_server(self):
def test_bad_host_header(self):
# https://corte.si/posts/code/pathod/pythonservers/index.html
to_send = "GET / HTTP/1.0\r\n Host: 0\r\n\r\n"
to_send = tobytes(to_send)
self.connect()
self.sock.send(to_send) |
def test_bad_host_header(self):
self.assertTrue(headers.get("date"))
def test_send_with_body(self):
to_send = "GET / HTTP/1.0\n" "Content-Length: 5\n\n"
to_send += "hello"
to_send = tobytes(to_send)
self.connect() | def test_bad_host_header(self):
self.assertTrue(headers.get("date"))
def test_send_with_body(self):
to_send = "GET / HTTP/1.0\r\nContent-Length: 5\r\n\r\n"
to_send += "hello"
to_send = tobytes(to_send)
self.connect() |
def test_send_with_body(self):
self.assertEqual(echo.body, b"hello")
def test_send_empty_body(self):
to_send = "GET / HTTP/1.0\n" "Content-Length: 0\n\n"
to_send = tobytes(to_send)
self.connect()
self.sock.send(to_send) | def test_send_with_body(self):
self.assertEqual(echo.body, b"hello")
def test_send_empty_body(self):
to_send = "GET / HTTP/1.0\r\nContent-Length: 0\r\n\r\n"
to_send = tobytes(to_send)
self.connect()
self.sock.send(to_send) |
def test_multiple_requests_without_body(self):
self.sock = orig_sock
def test_without_crlf(self):
data = "Echo\nthis\r\nplease"
s = tobytes(
"GET / HTTP/1.0\n"
"Connection: close\n"
"Content-Length: %d\n"
"\n"
"%s" % (len(data), da... | def test_multiple_requests_without_body(self):
self.sock = orig_sock
def test_without_crlf(self):
data = "Echo\r\nthis\r\nplease"
s = tobytes(
"GET / HTTP/1.0\r\n"
"Connection: close\r\n"
"Content-Length: %d\r\n"
"\r\n"
"%s" % (len... |
def test_large_body(self):
# 1024 characters.
body = "This string has 32 characters.\r\n" * 32
s = tobytes(
"GET / HTTP/1.0\n" "Content-Length: %d\n" "\n" "%s" % (len(body), body)
)
self.connect()
self.sock.send(s) | def test_large_body(self):
# 1024 characters.
body = "This string has 32 characters.\r\n" * 32
s = tobytes(
"GET / HTTP/1.0\r\nContent-Length: %d\r\n\r\n%s" % (len(body), body)
)
self.connect()
self.sock.send(s) |
def test_many_clients(self):
h.close()
def test_chunking_request_without_content(self):
header = tobytes("GET / HTTP/1.1\n" "Transfer-Encoding: chunked\n\n")
self.connect()
self.sock.send(header)
self.sock.send(b"0\r\n\r\n") | def test_many_clients(self):
h.close()
def test_chunking_request_without_content(self):
header = tobytes("GET / HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n")
self.connect()
self.sock.send(header)
self.sock.send(b"0\r\n\r\n") |
def test_chunking_request_with_content(self):
control_line = b"20;\r\n" # 20 hex = 32 dec
s = b"This string has 32 characters.\r\n"
expected = s * 12
header = tobytes("GET / HTTP/1.1\n" "Transfer-Encoding: chunked\n\n")
self.connect()
self.sock.send(header)
fp = ... | def test_chunking_request_with_content(self):
control_line = b"20;\r\n" # 20 hex = 32 dec
s = b"This string has 32 characters.\r\n"
expected = s * 12
header = tobytes("GET / HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n")
self.connect()
self.sock.send(header)
fp... |
def test_chunking_request_with_content(self):
def test_broken_chunked_encoding(self):
control_line = "20;\r\n" # 20 hex = 32 dec
s = "This string has 32 characters.\r\n"
to_send = "GET / HTTP/1.1\nTransfer-Encoding: chunked\n\n"
to_send += control_line + s
# garbage in input... | def test_chunking_request_with_content(self):
def test_broken_chunked_encoding(self):
control_line = "20;\r\n" # 20 hex = 32 dec
s = "This string has 32 characters.\r\n"
to_send = "GET / HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n"
to_send += control_line + s + "\r\n"
# g... |
def test_broken_chunked_encoding(self):
self.assertline(line, "400", "Bad Request", "HTTP/1.1")
cl = int(headers["content-length"])
self.assertEqual(cl, len(response_body))
self.assertEqual(
sorted(headers.keys()), ["content-length", "content-type", "date", "server"]
... | def test_broken_chunked_encoding(self):
self.assertline(line, "400", "Bad Request", "HTTP/1.1")
cl = int(headers["content-length"])
self.assertEqual(cl, len(response_body))
self.assertTrue(b"Chunk not properly terminated" in response_body)
self.assertEqual(
sorted(hea... |
def test_keepalive_http_10(self):
# Handling of Keep-Alive within HTTP 1.0
data = "Default: Don't keep me alive"
s = tobytes(
"GET / HTTP/1.0\n" "Content-Length: %d\n" "\n" "%s" % (len(data), data)
)
self.connect()
self.sock.send(s) | def test_keepalive_http_10(self):
# Handling of Keep-Alive within HTTP 1.0
data = "Default: Don't keep me alive"
s = tobytes(
"GET / HTTP/1.0\r\nContent-Length: %d\r\n\r\n%s" % (len(data), data)
)
self.connect()
self.sock.send(s) |
def test_keepalive_http10_explicit(self):
# the corresponding header
data = "Keep me alive"
s = tobytes(
"GET / HTTP/1.0\n"
"Connection: Keep-Alive\n"
"Content-Length: %d\n"
"\n"
"%s" % (len(data), data)
)
self.connect() | def test_keepalive_http10_explicit(self):
# the corresponding header
data = "Keep me alive"
s = tobytes(
"GET / HTTP/1.0\r\n"
"Connection: Keep-Alive\r\n"
"Content-Length: %d\r\n"
"\r\n"
"%s" % (len(data), data)
)
self.c... |
def test_keepalive_http_11(self):
# All connections are kept alive, unless stated otherwise
data = "Default: Keep me alive"
s = tobytes(
"GET / HTTP/1.1\n" "Content-Length: %d\n" "\n" "%s" % (len(data), data)
)
self.connect()
self.sock.send(s) | def test_keepalive_http_11(self):
# All connections are kept alive, unless stated otherwise
data = "Default: Keep me alive"
s = tobytes(
"GET / HTTP/1.1\r\nContent-Length: %d\r\n\r\n%s" % (len(data), data)
)
self.connect()
self.sock.send(s) |
def test_keepalive_http11_explicit(self):
# Explicitly set keep-alive
data = "Default: Keep me alive"
s = tobytes(
"GET / HTTP/1.1\n"
"Connection: keep-alive\n"
"Content-Length: %d\n"
"\n"
"%s" % (len(data), data)
)
self... | def test_keepalive_http11_explicit(self):
# Explicitly set keep-alive
data = "Default: Keep me alive"
s = tobytes(
"GET / HTTP/1.1\r\n"
"Connection: keep-alive\r\n"
"Content-Length: %d\r\n"
"\r\n"
"%s" % (len(data), data)
)
... |
def test_keepalive_http11_connclose(self):
# specifying Connection: close explicitly
data = "Don't keep me alive"
s = tobytes(
"GET / HTTP/1.1\n"
"Connection: close\n"
"Content-Length: %d\n"
"\n"
"%s" % (len(data), data)
)
... | def test_keepalive_http11_connclose(self):
# specifying Connection: close explicitly
data = "Don't keep me alive"
s = tobytes(
"GET / HTTP/1.1\r\n"
"Connection: close\r\n"
"Content-Length: %d\r\n"
"\r\n"
"%s" % (len(data), data)
... |
def test_keepalive_http11_connclose(self):
def test_proxy_headers(self):
to_send = (
"GET / HTTP/1.0\n"
"Content-Length: 0\n"
"Host: www.google.com:8080\n"
"X-Forwarded-For: 192.168.1.1\n"
"X-Forwarded-Proto: https\n"
"X-Forwarded-Port... | def test_keepalive_http11_connclose(self):
def test_proxy_headers(self):
to_send = (
"GET / HTTP/1.0\r\n"
"Content-Length: 0\r\n"
"Host: www.google.com:8080\r\n"
"X-Forwarded-For: 192.168.1.1\r\n"
"X-Forwarded-Proto: https\r\n"
"X-Forw... |
def test_expect_continue(self):
# specifying Connection: close explicitly
data = "I have expectations"
to_send = tobytes(
"GET / HTTP/1.1\n"
"Connection: close\n"
"Content-Length: %d\n"
"Expect: 100-continue\n"
"\n"
"%s" % (... | def test_expect_continue(self):
# specifying Connection: close explicitly
data = "I have expectations"
to_send = tobytes(
"GET / HTTP/1.1\r\n"
"Connection: close\r\n"
"Content-Length: %d\r\n"
"Expect: 100-continue\r\n"
"\r\n"
... |
def test_short_body(self):
# check to see if server closes connection when body is too short
# for cl header
to_send = tobytes(
"GET /short_body HTTP/1.0\n"
"Connection: Keep-Alive\n"
"Content-Length: 0\n"
"\n"
)
self.connect()
... | def test_short_body(self):
# check to see if server closes connection when body is too short
# for cl header
to_send = tobytes(
"GET /short_body HTTP/1.0\r\n"
"Connection: Keep-Alive\r\n"
"Content-Length: 0\r\n"
"\r\n"
)
self.connec... |
def test_long_body(self):
# check server doesnt close connection when body is too short
# for cl header
to_send = tobytes(
"GET /long_body HTTP/1.0\n"
"Connection: Keep-Alive\n"
"Content-Length: 0\n"
"\n"
)
self.connect()
se... | def test_long_body(self):
# check server doesnt close connection when body is too short
# for cl header
to_send = tobytes(
"GET /long_body HTTP/1.0\r\n"
"Connection: Keep-Alive\r\n"
"Content-Length: 0\r\n"
"\r\n"
)
self.connect()
... |
def tearDown(self):
def test_http10_generator(self):
body = string.ascii_letters
to_send = (
"GET / HTTP/1.0\n"
"Connection: Keep-Alive\n"
"Content-Length: %d\n\n" % len(body)
)
to_send += body
to_send = tobytes(to_send) | def tearDown(self):
def test_http10_generator(self):
body = string.ascii_letters
to_send = (
"GET / HTTP/1.0\r\n"
"Connection: Keep-Alive\r\n"
"Content-Length: %d\r\n\r\n" % len(body)
)
to_send += body
to_send = tobytes(to_send) |
def test_http10_generator(self):
def test_http10_list(self):
body = string.ascii_letters
to_send = (
"GET /list HTTP/1.0\n"
"Connection: Keep-Alive\n"
"Content-Length: %d\n\n" % len(body)
)
to_send += body
to_send = tobytes(to_send) | def test_http10_generator(self):
def test_http10_list(self):
body = string.ascii_letters
to_send = (
"GET /list HTTP/1.0\r\n"
"Connection: Keep-Alive\r\n"
"Content-Length: %d\r\n\r\n" % len(body)
)
to_send += body
to_send = tobytes(to_send) |
def test_http10_list(self):
def test_http10_listlentwo(self):
body = string.ascii_letters
to_send = (
"GET /list_lentwo HTTP/1.0\n"
"Connection: Keep-Alive\n"
"Content-Length: %d\n\n" % len(body)
)
to_send += body
to_send = tobytes(to_send) | def test_http10_list(self):
def test_http10_listlentwo(self):
body = string.ascii_letters
to_send = (
"GET /list_lentwo HTTP/1.0\r\n"
"Connection: Keep-Alive\r\n"
"Content-Length: %d\r\n\r\n" % len(body)
)
to_send += body
to_send = tobytes(... |
def test_http10_listlentwo(self):
def test_http11_generator(self):
body = string.ascii_letters
to_send = "GET / HTTP/1.1\n" "Content-Length: %s\n\n" % len(body)
to_send += body
to_send = tobytes(to_send)
self.connect() | def test_http10_listlentwo(self):
def test_http11_generator(self):
body = string.ascii_letters
to_send = "GET / HTTP/1.1\r\nContent-Length: %s\r\n\r\n" % len(body)
to_send += body
to_send = tobytes(to_send)
self.connect() |
def test_http11_generator(self):
def test_http11_list(self):
body = string.ascii_letters
to_send = "GET /list HTTP/1.1\n" "Content-Length: %d\n\n" % len(body)
to_send += body
to_send = tobytes(to_send)
self.connect() | def test_http11_generator(self):
def test_http11_list(self):
body = string.ascii_letters
to_send = "GET /list HTTP/1.1\r\nContent-Length: %d\r\n\r\n" % len(body)
to_send += body
to_send = tobytes(to_send)
self.connect() |
def test_http11_list(self):
def test_http11_listlentwo(self):
body = string.ascii_letters
to_send = "GET /list_lentwo HTTP/1.1\n" "Content-Length: %s\n\n" % len(body)
to_send += body
to_send = tobytes(to_send)
self.connect() | def test_http11_list(self):
def test_http11_listlentwo(self):
body = string.ascii_letters
to_send = "GET /list_lentwo HTTP/1.1\r\nContent-Length: %s\r\n\r\n" % len(body)
to_send += body
to_send = tobytes(to_send)
self.connect() |
def test_short_body(self):
# check to see if server closes connection when body is too short
# for cl header
to_send = tobytes(
"GET /short_body HTTP/1.0\n"
"Connection: Keep-Alive\n"
"Content-Length: 0\n"
"\n"
)
self.connect()
... | def test_short_body(self):
# check to see if server closes connection when body is too short
# for cl header
to_send = tobytes(
"GET /short_body HTTP/1.0\r\n"
"Connection: Keep-Alive\r\n"
"Content-Length: 0\r\n"
"\r\n"
)
self.connec... |
def test_long_body(self):
# check server doesnt close connection when body is too long
# for cl header
to_send = tobytes(
"GET /long_body HTTP/1.0\n"
"Connection: Keep-Alive\n"
"Content-Length: 0\n"
"\n"
)
self.connect()
sel... | def test_long_body(self):
# check server doesnt close connection when body is too long
# for cl header
to_send = tobytes(
"GET /long_body HTTP/1.0\r\n"
"Connection: Keep-Alive\r\n"
"Content-Length: 0\r\n"
"\r\n"
)
self.connect()
... |
def test_equal_body(self):
# check server doesnt close connection when body is equal to
# cl header
to_send = tobytes(
"GET /equal_body HTTP/1.0\n"
"Connection: Keep-Alive\n"
"Content-Length: 0\n"
"\n"
)
self.connect()
self.... | def test_equal_body(self):
# check server doesnt close connection when body is equal to
# cl header
to_send = tobytes(
"GET /equal_body HTTP/1.0\r\n"
"Connection: Keep-Alive\r\n"
"Content-Length: 0\r\n"
"\r\n"
)
self.connect()
... |
def test_equal_body(self):
def test_no_content_length(self):
# wtf happens when there's no content-length
to_send = tobytes(
"GET /no_content_length HTTP/1.0\n"
"Connection: Keep-Alive\n"
"Content-Length: 0\n"
"\n"
)
self.connect()
... | def test_equal_body(self):
def test_no_content_length(self):
# wtf happens when there's no content-length
to_send = tobytes(
"GET /no_content_length HTTP/1.0\r\n"
"Connection: Keep-Alive\r\n"
"Content-Length: 0\r\n"
"\r\n"
)
self.connec... |
def tearDown(self):
def test_request_body_too_large_with_wrong_cl_http10(self):
body = "a" * self.toobig
to_send = "GET / HTTP/1.0\n" "Content-Length: 5\n\n"
to_send += body
to_send = tobytes(to_send)
self.connect() | def tearDown(self):
def test_request_body_too_large_with_wrong_cl_http10(self):
body = "a" * self.toobig
to_send = "GET / HTTP/1.0\r\nContent-Length: 5\r\n\r\n"
to_send += body
to_send = tobytes(to_send)
self.connect() |
def test_request_body_too_large_with_wrong_cl_http10(self):
def test_request_body_too_large_with_wrong_cl_http10_keepalive(self):
body = "a" * self.toobig
to_send = "GET / HTTP/1.0\n" "Content-Length: 5\n" "Connection: Keep-Alive\n\n"
to_send += body
to_send = tobytes(to_send)
... | def test_request_body_too_large_with_wrong_cl_http10(self):
def test_request_body_too_large_with_wrong_cl_http10_keepalive(self):
body = "a" * self.toobig
to_send = "GET / HTTP/1.0\r\nContent-Length: 5\r\nConnection: Keep-Alive\r\n\r\n"
to_send += body
to_send = tobytes(to_send)
... |
def test_request_body_too_large_with_wrong_cl_http10_keepalive(self):
def test_request_body_too_large_with_no_cl_http10(self):
body = "a" * self.toobig
to_send = "GET / HTTP/1.0\n\n"
to_send += body
to_send = tobytes(to_send)
self.connect() | def test_request_body_too_large_with_wrong_cl_http10_keepalive(self):
def test_request_body_too_large_with_no_cl_http10(self):
body = "a" * self.toobig
to_send = "GET / HTTP/1.0\r\n\r\n"
to_send += body
to_send = tobytes(to_send)
self.connect() |
def test_request_body_too_large_with_no_cl_http10(self):
def test_request_body_too_large_with_no_cl_http10_keepalive(self):
body = "a" * self.toobig
to_send = "GET / HTTP/1.0\nConnection: Keep-Alive\n\n"
to_send += body
to_send = tobytes(to_send)
self.connect() | def test_request_body_too_large_with_no_cl_http10(self):
def test_request_body_too_large_with_no_cl_http10_keepalive(self):
body = "a" * self.toobig
to_send = "GET / HTTP/1.0\r\nConnection: Keep-Alive\r\n\r\n"
to_send += body
to_send = tobytes(to_send)
self.connect() |
def test_request_body_too_large_with_no_cl_http10_keepalive(self):
def test_request_body_too_large_with_wrong_cl_http11(self):
body = "a" * self.toobig
to_send = "GET / HTTP/1.1\n" "Content-Length: 5\n\n"
to_send += body
to_send = tobytes(to_send)
self.connect() | def test_request_body_too_large_with_no_cl_http10_keepalive(self):
def test_request_body_too_large_with_wrong_cl_http11(self):
body = "a" * self.toobig
to_send = "GET / HTTP/1.1\r\nContent-Length: 5\r\n\r\n"
to_send += body
to_send = tobytes(to_send)
self.connect() |
def test_request_body_too_large_with_wrong_cl_http11(self):
def test_request_body_too_large_with_wrong_cl_http11_connclose(self):
body = "a" * self.toobig
to_send = "GET / HTTP/1.1\nContent-Length: 5\nConnection: close\n\n"
to_send += body
to_send = tobytes(to_send)
self.con... | def test_request_body_too_large_with_wrong_cl_http11(self):
def test_request_body_too_large_with_wrong_cl_http11_connclose(self):
body = "a" * self.toobig
to_send = "GET / HTTP/1.1\r\nContent-Length: 5\r\nConnection: close\r\n\r\n"
to_send += body
to_send = tobytes(to_send)
... |
def test_request_body_too_large_with_wrong_cl_http11_connclose(self):
def test_request_body_too_large_with_no_cl_http11(self):
body = "a" * self.toobig
to_send = "GET / HTTP/1.1\n\n"
to_send += body
to_send = tobytes(to_send)
self.connect() | def test_request_body_too_large_with_wrong_cl_http11_connclose(self):
def test_request_body_too_large_with_no_cl_http11(self):
body = "a" * self.toobig
to_send = "GET / HTTP/1.1\r\n\r\n"
to_send += body
to_send = tobytes(to_send)
self.connect() |
def test_request_body_too_large_with_no_cl_http11(self):
def test_request_body_too_large_with_no_cl_http11_connclose(self):
body = "a" * self.toobig
to_send = "GET / HTTP/1.1\nConnection: close\n\n"
to_send += body
to_send = tobytes(to_send)
self.connect() | def test_request_body_too_large_with_no_cl_http11(self):
def test_request_body_too_large_with_no_cl_http11_connclose(self):
body = "a" * self.toobig
to_send = "GET / HTTP/1.1\r\nConnection: close\r\n\r\n"
to_send += body
to_send = tobytes(to_send)
self.connect() |
def test_request_body_too_large_with_no_cl_http11_connclose(self):
def test_request_body_too_large_chunked_encoding(self):
control_line = "20;\r\n" # 20 hex = 32 dec
s = "This string has 32 characters.\r\n"
to_send = "GET / HTTP/1.1\nTransfer-Encoding: chunked\n\n"
repeat = control_... | def test_request_body_too_large_with_no_cl_http11_connclose(self):
def test_request_body_too_large_chunked_encoding(self):
control_line = "20;\r\n" # 20 hex = 32 dec
s = "This string has 32 characters.\r\n"
to_send = "GET / HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n"
repeat = co... |
def tearDown(self):
self.stop_subprocess()
def test_before_start_response_http_10(self):
to_send = "GET /before_start_response HTTP/1.0\n\n"
to_send = tobytes(to_send)
self.connect()
self.sock.send(to_send) | def tearDown(self):
self.stop_subprocess()
def test_before_start_response_http_10(self):
to_send = "GET /before_start_response HTTP/1.0\r\n\r\n"
to_send = tobytes(to_send)
self.connect()
self.sock.send(to_send) |
def test_before_start_response_http_10(self):
self.assertRaises(ConnectionClosed, read_http, fp)
def test_before_start_response_http_11(self):
to_send = "GET /before_start_response HTTP/1.1\n\n"
to_send = tobytes(to_send)
self.connect()
self.sock.send(to_send) | def test_before_start_response_http_10(self):
self.assertRaises(ConnectionClosed, read_http, fp)
def test_before_start_response_http_11(self):
to_send = "GET /before_start_response HTTP/1.1\r\n\r\n"
to_send = tobytes(to_send)
self.connect()
self.sock.send(to_send) |
def test_before_start_response_http_11(self):
self.assertEqual(cl, len(response_body))
self.assertTrue(response_body.startswith(b"Internal Server Error"))
self.assertEqual(
sorted(headers.keys()), ["content-length", "content-type", "date", "server"]
)
# connection has... | def test_before_start_response_http_11(self):
self.assertEqual(cl, len(response_body))
self.assertTrue(response_body.startswith(b"Internal Server Error"))
self.assertEqual(
sorted(headers.keys()), ["connection", "content-length", "content-type", "date", "server"]
)
# ... |
def test_before_start_response_http_11(self):
def test_before_start_response_http_11_close(self):
to_send = tobytes(
"GET /before_start_response HTTP/1.1\n" "Connection: close\n\n"
)
self.connect()
self.sock.send(to_send) | def test_before_start_response_http_11(self):
def test_before_start_response_http_11_close(self):
to_send = tobytes(
"GET /before_start_response HTTP/1.1\r\nConnection: close\r\n\r\n"
)
self.connect()
self.sock.send(to_send) |
def test_before_start_response_http_11_close(self):
self.assertRaises(ConnectionClosed, read_http, fp)
def test_after_start_response_http10(self):
to_send = "GET /after_start_response HTTP/1.0\n\n"
to_send = tobytes(to_send)
self.connect()
self.sock.send(to_send) | def test_before_start_response_http_11_close(self):
self.assertRaises(ConnectionClosed, read_http, fp)
def test_after_start_response_http10(self):
to_send = "GET /after_start_response HTTP/1.0\r\n\r\n"
to_send = tobytes(to_send)
self.connect()
self.sock.send(to_send) |
def test_after_start_response_http10(self):
self.assertRaises(ConnectionClosed, read_http, fp)
def test_after_start_response_http11(self):
to_send = "GET /after_start_response HTTP/1.1\n\n"
to_send = tobytes(to_send)
self.connect()
self.sock.send(to_send) | def test_after_start_response_http10(self):
self.assertRaises(ConnectionClosed, read_http, fp)
def test_after_start_response_http11(self):
to_send = "GET /after_start_response HTTP/1.1\r\n\r\n"
to_send = tobytes(to_send)
self.connect()
self.sock.send(to_send) |
def test_after_start_response_http11(self):
self.assertEqual(cl, len(response_body))
self.assertTrue(response_body.startswith(b"Internal Server Error"))
self.assertEqual(
sorted(headers.keys()), ["content-length", "content-type", "date", "server"]
)
# connection has b... | def test_after_start_response_http11(self):
self.assertEqual(cl, len(response_body))
self.assertTrue(response_body.startswith(b"Internal Server Error"))
self.assertEqual(
sorted(headers.keys()), ["connection", "content-length", "content-type", "date", "server"]
)
# co... |
def test_after_start_response_http11(self):
def test_after_start_response_http11_close(self):
to_send = tobytes(
"GET /after_start_response HTTP/1.1\n" "Connection: close\n\n"
)
self.connect()
self.sock.send(to_send) | def test_after_start_response_http11(self):
def test_after_start_response_http11_close(self):
to_send = tobytes(
"GET /after_start_response HTTP/1.1\r\nConnection: close\r\n\r\n"
)
self.connect()
self.sock.send(to_send) |
def test_after_start_response_http11_close(self):
self.assertRaises(ConnectionClosed, read_http, fp)
def test_after_write_cb(self):
to_send = "GET /after_write_cb HTTP/1.1\n\n"
to_send = tobytes(to_send)
self.connect()
self.sock.send(to_send) | def test_after_start_response_http11_close(self):
self.assertRaises(ConnectionClosed, read_http, fp)
def test_after_write_cb(self):
to_send = "GET /after_write_cb HTTP/1.1\r\n\r\n"
to_send = tobytes(to_send)
self.connect()
self.sock.send(to_send) |
def test_after_write_cb(self):
self.assertRaises(ConnectionClosed, read_http, fp)
def test_in_generator(self):
to_send = "GET /in_generator HTTP/1.1\n\n"
to_send = tobytes(to_send)
self.connect()
self.sock.send(to_send) | def test_after_write_cb(self):
self.assertRaises(ConnectionClosed, read_http, fp)
def test_in_generator(self):
to_send = "GET /in_generator HTTP/1.1\r\n\r\n"
to_send = tobytes(to_send)
self.connect()
self.sock.send(to_send) |
def tearDown(self):
self.stop_subprocess()
def test_filelike_http11(self):
to_send = "GET /filelike HTTP/1.1\n\n"
to_send = tobytes(to_send)
self.connect() | def tearDown(self):
self.stop_subprocess()
def test_filelike_http11(self):
to_send = "GET /filelike HTTP/1.1\r\n\r\n"
to_send = tobytes(to_send)
self.connect() |
def test_filelike_http11(self):
# connection has not been closed
def test_filelike_nocl_http11(self):
to_send = "GET /filelike_nocl HTTP/1.1\n\n"
to_send = tobytes(to_send)
self.connect() | def test_filelike_http11(self):
# connection has not been closed
def test_filelike_nocl_http11(self):
to_send = "GET /filelike_nocl HTTP/1.1\r\n\r\n"
to_send = tobytes(to_send)
self.connect() |
def test_filelike_nocl_http11(self):
# connection has not been closed
def test_filelike_shortcl_http11(self):
to_send = "GET /filelike_shortcl HTTP/1.1\n\n"
to_send = tobytes(to_send)
self.connect() | def test_filelike_nocl_http11(self):
# connection has not been closed
def test_filelike_shortcl_http11(self):
to_send = "GET /filelike_shortcl HTTP/1.1\r\n\r\n"
to_send = tobytes(to_send)
self.connect() |
def test_filelike_shortcl_http11(self):
# connection has not been closed
def test_filelike_longcl_http11(self):
to_send = "GET /filelike_longcl HTTP/1.1\n\n"
to_send = tobytes(to_send)
self.connect() | def test_filelike_shortcl_http11(self):
# connection has not been closed
def test_filelike_longcl_http11(self):
to_send = "GET /filelike_longcl HTTP/1.1\r\n\r\n"
to_send = tobytes(to_send)
self.connect() |
def test_filelike_longcl_http11(self):
# connection has not been closed
def test_notfilelike_http11(self):
to_send = "GET /notfilelike HTTP/1.1\n\n"
to_send = tobytes(to_send)
self.connect() | def test_filelike_longcl_http11(self):
# connection has not been closed
def test_notfilelike_http11(self):
to_send = "GET /notfilelike HTTP/1.1\r\n\r\n"
to_send = tobytes(to_send)
self.connect() |
def test_notfilelike_http11(self):
# connection has not been closed
def test_notfilelike_iobase_http11(self):
to_send = "GET /notfilelike_iobase HTTP/1.1\n\n"
to_send = tobytes(to_send)
self.connect() | def test_notfilelike_http11(self):
# connection has not been closed
def test_notfilelike_iobase_http11(self):
to_send = "GET /notfilelike_iobase HTTP/1.1\r\n\r\n"
to_send = tobytes(to_send)
self.connect() |
def test_notfilelike_iobase_http11(self):
# connection has not been closed
def test_notfilelike_nocl_http11(self):
to_send = "GET /notfilelike_nocl HTTP/1.1\n\n"
to_send = tobytes(to_send)
self.connect() | def test_notfilelike_iobase_http11(self):
# connection has not been closed
def test_notfilelike_nocl_http11(self):
to_send = "GET /notfilelike_nocl HTTP/1.1\r\n\r\n"
to_send = tobytes(to_send)
self.connect() |
def test_notfilelike_nocl_http11(self):
self.assertRaises(ConnectionClosed, read_http, fp)
def test_notfilelike_shortcl_http11(self):
to_send = "GET /notfilelike_shortcl HTTP/1.1\n\n"
to_send = tobytes(to_send)
self.connect() | def test_notfilelike_nocl_http11(self):
self.assertRaises(ConnectionClosed, read_http, fp)
def test_notfilelike_shortcl_http11(self):
to_send = "GET /notfilelike_shortcl HTTP/1.1\r\n\r\n"
to_send = tobytes(to_send)
self.connect() |
def test_notfilelike_shortcl_http11(self):
# connection has not been closed
def test_notfilelike_longcl_http11(self):
to_send = "GET /notfilelike_longcl HTTP/1.1\n\n"
to_send = tobytes(to_send)
self.connect() | def test_notfilelike_shortcl_http11(self):
# connection has not been closed
def test_notfilelike_longcl_http11(self):
to_send = "GET /notfilelike_longcl HTTP/1.1\r\n\r\n"
to_send = tobytes(to_send)
self.connect() |
def test_notfilelike_longcl_http11(self):
self.assertRaises(ConnectionClosed, read_http, fp)
def test_filelike_http10(self):
to_send = "GET /filelike HTTP/1.0\n\n"
to_send = tobytes(to_send)
self.connect() | def test_notfilelike_longcl_http11(self):
self.assertRaises(ConnectionClosed, read_http, fp)
def test_filelike_http10(self):
to_send = "GET /filelike HTTP/1.0\r\n\r\n"
to_send = tobytes(to_send)
self.connect() |
def test_filelike_http10(self):
self.assertRaises(ConnectionClosed, read_http, fp)
def test_filelike_nocl_http10(self):
to_send = "GET /filelike_nocl HTTP/1.0\n\n"
to_send = tobytes(to_send)
self.connect() | def test_filelike_http10(self):
self.assertRaises(ConnectionClosed, read_http, fp)
def test_filelike_nocl_http10(self):
to_send = "GET /filelike_nocl HTTP/1.0\r\n\r\n"
to_send = tobytes(to_send)
self.connect() |
def test_filelike_nocl_http10(self):
self.assertRaises(ConnectionClosed, read_http, fp)
def test_notfilelike_http10(self):
to_send = "GET /notfilelike HTTP/1.0\n\n"
to_send = tobytes(to_send)
self.connect() | def test_filelike_nocl_http10(self):
self.assertRaises(ConnectionClosed, read_http, fp)
def test_notfilelike_http10(self):
to_send = "GET /notfilelike HTTP/1.0\r\n\r\n"
to_send = tobytes(to_send)
self.connect() |
def test_notfilelike_http10(self):
self.assertRaises(ConnectionClosed, read_http, fp)
def test_notfilelike_nocl_http10(self):
to_send = "GET /notfilelike_nocl HTTP/1.0\n\n"
to_send = tobytes(to_send)
self.connect() | def test_notfilelike_http10(self):
self.assertRaises(ConnectionClosed, read_http, fp)
def test_notfilelike_nocl_http10(self):
to_send = "GET /notfilelike_nocl HTTP/1.0\r\n\r\n"
to_send = tobytes(to_send)
self.connect() |
def read_http(fp): # pragma: no cover
header_lines = []
while True:
line = fp.readline()
if line in (b"\r\n", b"\n", b""):
break
else:
header_lines.append(line) | def read_http(fp): # pragma: no cover
header_lines = []
while True:
line = fp.readline()
if line in (b"\r\n", b"\r\n", b""):
break
else:
header_lines.append(line) |
"""
import unittest
from waitress.compat import (
text_,
tobytes,
)
class TestHTTPRequestParser(unittest.TestCase): | """
import unittest
from waitress.compat import text_, tobytes
class TestHTTPRequestParser(unittest.TestCase): |
def test_get_body_stream_nonNone(self):
result = self.parser.get_body_stream()
self.assertEqual(result, body_rcv)
def test_received_nonsense_with_double_cr(self):
data = b"""\
HTTP/1.0 GET /foobar
"""
result = self.parser.received(data)
self.assertEqual(result, 22)
... | def test_get_body_stream_nonNone(self):
result = self.parser.get_body_stream()
self.assertEqual(result, body_rcv)
def test_received_get_no_headers(self):
data = b"HTTP/1.0 GET /foobar\r\n\r\n"
result = self.parser.received(data)
self.assertEqual(result, 24)
self.asse... |
def test_received_cl_too_large(self):
from waitress.utilities import RequestEntityTooLarge
self.parser.adj.max_request_body_size = 2
data = b"""\
GET /foobar HTTP/8.4
Content-Length: 10
"""
result = self.parser.received(data)
self.assertEqual(result, 41)
self.assertTrue... | def test_received_cl_too_large(self):
from waitress.utilities import RequestEntityTooLarge
self.parser.adj.max_request_body_size = 2
data = b"GET /foobar HTTP/8.4\r\nContent-Length: 10\r\n\r\n"
result = self.parser.received(data)
self.assertEqual(result, 44)
self.assertT... |
def test_received_headers_too_large(self):
from waitress.utilities import RequestHeaderFieldsTooLarge
self.parser.adj.max_request_header_size = 2
data = b"""\
GET /foobar HTTP/8.4
X-Foo: 1
"""
result = self.parser.received(data)
self.assertEqual(result, 30)
self.assertTr... | def test_received_headers_too_large(self):
from waitress.utilities import RequestHeaderFieldsTooLarge
self.parser.adj.max_request_header_size = 2
data = b"GET /foobar HTTP/8.4\r\nX-Foo: 1\r\n\r\n"
result = self.parser.received(data)
self.assertEqual(result, 34)
self.asse... |
def test_received_body_too_large(self):
from waitress.utilities import RequestEntityTooLarge
self.parser.adj.max_request_body_size = 2
data = b"""\
GET /foobar HTTP/1.1
Transfer-Encoding: chunked
X-Foo: 1
20;\r\n
This string has 32 characters\r\n
0\r\n\r\n"""
result = self.parser.recei... | def test_received_body_too_large(self):
from waitress.utilities import RequestEntityTooLarge
self.parser.adj.max_request_body_size = 2
data = (
b"GET /foobar HTTP/1.1\r\n"
b"Transfer-Encoding: chunked\r\n"
b"X-Foo: 1\r\n"
b"\r\n"
b"1d;... |
def test_received_body_too_large(self):
def test_received_error_from_parser(self):
from waitress.utilities import BadRequest
data = b"""\
GET /foobar HTTP/1.1
Transfer-Encoding: chunked
X-Foo: 1
garbage
"""
# header
result = self.parser.received(data)
# body
result ... | def test_received_body_too_large(self):
def test_received_error_from_parser(self):
from waitress.utilities import BadRequest
data = (
b"GET /foobar HTTP/1.1\r\n"
b"Transfer-Encoding: chunked\r\n"
b"X-Foo: 1\r\n"
b"\r\n"
b"garbage\r\n"
... |
def test_close_with_no_body_rcv(self):
self.parser.body_rcv = None
self.parser.close() # doesn't raise
class Test_split_uri(unittest.TestCase):
def _callFUT(self, uri): | def test_close_with_no_body_rcv(self):
self.parser.body_rcv = None
self.parser.close() # doesn't raise
def test_parse_header_lf_only(self):
from waitress.parser import ParsingError
data = b"GET /foobar HTTP/8.4\nfoo: bar"
try:
self.parser.parse_header(data)
... |
def _callFUT(self, data):
return get_header_lines(data)
def test_get_header_lines(self):
result = self._callFUT(b"slam\nslim")
self.assertEqual(result, [b"slam", b"slim"])
def test_get_header_lines_folded(self): | def _callFUT(self, data):
return get_header_lines(data)
def test_get_header_lines(self):
result = self._callFUT(b"slam\r\nslim")
self.assertEqual(result, [b"slam", b"slim"])
def test_get_header_lines_folded(self): |
def test_get_header_lines_folded(self):
# interpreting the field value or forwarding the message downstream.
# We are just preserving the whitespace that indicates folding.
result = self._callFUT(b"slim\n slam")
self.assertEqual(result, [b"slim slam"])
def test_get_header_lines_tab... | def test_get_header_lines_folded(self):
# interpreting the field value or forwarding the message downstream.
# We are just preserving the whitespace that indicates folding.
result = self._callFUT(b"slim\r\n slam")
self.assertEqual(result, [b"slim slam"])
def test_get_header_lines_t... |
def setUp(self):
def feed(self, data):
parser = self.parser
for n in range(100): # make sure we never loop forever
consumed = parser.received(data)
data = data[consumed:]
if parser.completed:
return
raise ValueError("Looping") # pragma: ... | def setUp(self):
def feed(self, data):
parser = self.parser
for n in range(100): # make sure we never loop forever
consumed = parser.received(data)
data = data[consumed:]
if parser.completed:
return
raise ValueError("Looping") # pragma... |
def testSimpleGET(self):
self.assertFalse(parser.empty)
self.assertEqual(
parser.headers,
{"FIRSTNAME": "mickey", "LASTNAME": "Mouse", "CONTENT_LENGTH": "7",},
)
self.assertEqual(parser.path, "/foobar")
self.assertEqual(parser.command, "GET")
self.... | def testSimpleGET(self):
self.assertFalse(parser.empty)
self.assertEqual(
parser.headers,
{"FIRSTNAME": "mickey", "LASTNAME": "Mouse", "CONTENT_LENGTH": "6",},
)
self.assertEqual(parser.path, "/foobar")
self.assertEqual(parser.command, "GET")
self.... |
def testComplexGET(self):
self.assertFalse(parser.empty)
self.assertEqual(
parser.headers,
{"FIRSTNAME": "mickey", "LASTNAME": "Mouse", "CONTENT_LENGTH": "10",},
)
# path should be utf-8 encoded
self.assertEqual( | def testComplexGET(self):
self.assertFalse(parser.empty)
self.assertEqual(
parser.headers,
{"FIRSTNAME": "mickey", "LASTNAME": "Mouse", "CONTENT_LENGTH": "10"},
)
# path should be utf-8 encoded
self.assertEqual( |
def testComplexGET(self):
self.assertEqual(parser.get_body_stream().getvalue(), b"Hello mick")
def testProxyGET(self):
data = b"""\
GET https://example.com:8080/foobar HTTP/8.4
content-length: 7
Hello.
"""
parser = self.parser
self.feed(data)
self.assertTrue(parser.complete... | def testComplexGET(self):
self.assertEqual(parser.get_body_stream().getvalue(), b"Hello mick")
def testProxyGET(self):
data = (
b"GET https://example.com:8080/foobar HTTP/8.4\r\n"
b"content-length: 6\r\n"
b"\r\n"
b"Hello."
)
parser = s... |
def test_received_control_line_notfinished(self):
def test_received_control_line_finished_garbage_in_input(self):
buf = DummyBuffer()
inst = self._makeOne(buf)
result = inst.received(b"garbage\n")
self.assertEqual(result, 8)
self.assertTrue(inst.error)
def test_received_... | def test_received_control_line_notfinished(self):
def test_received_control_line_finished_garbage_in_input(self):
buf = DummyBuffer()
inst = self._makeOne(buf)
result = inst.received(b"garbage\r\n")
self.assertEqual(result, 9)
self.assertTrue(inst.error)
def test_receive... |
def test_received_trailer_startswith_lf(self):
inst.all_chunks_received = True
result = inst.received(b"\n")
self.assertEqual(result, 1)
self.assertEqual(inst.completed, True)
def test_received_trailer_not_finished(self):
buf = DummyBuffer() | def test_received_trailer_startswith_lf(self):
inst.all_chunks_received = True
result = inst.received(b"\n")
self.assertEqual(result, 1)
self.assertEqual(inst.completed, False)
def test_received_trailer_not_finished(self):
buf = DummyBuffer() |
def test___len__(self):
inst = self._makeOne(buf)
self.assertEqual(inst.__len__(), 2)
class DummyBuffer(object):
def __init__(self, data=None): | def test___len__(self):
inst = self._makeOne(buf)
self.assertEqual(inst.__len__(), 2)
def test_received_chunk_is_properly_terminated(self):
buf = DummyBuffer()
inst = self._makeOne(buf)
data = b"4\r\nWiki\r\n"
result = inst.received(data)
self.assertEqual(res... |
def test_execute_http_11(self):
inst.version = "1.1"
inst.execute()
lines = filter_lines(inst.channel.written)
self.assertEqual(len(lines), 8)
self.assertEqual(lines[0], b"HTTP/1.1 432 Too Ugly")
self.assertEqual(lines[1], b"Content-Length: 43")
self.assertEqual(l... | def test_execute_http_11(self):
inst.version = "1.1"
inst.execute()
lines = filter_lines(inst.channel.written)
self.assertEqual(len(lines), 9)
self.assertEqual(lines[0], b"HTTP/1.1 432 Too Ugly")
self.assertEqual(lines[1], b"Connection: close")
self.assertEqual(li... |
def test_execute_http_11_close(self):
self.assertEqual(lines[7], b"body")
self.assertEqual(lines[8], b"(generated by waitress)")
def test_execute_http_11_keep(self):
inst = self._makeOne()
inst.version = "1.1"
inst.request.headers["CONNECTION"] = "keep-alive"
inst.ex... | def test_execute_http_11_close(self):
self.assertEqual(lines[7], b"body")
self.assertEqual(lines[8], b"(generated by waitress)")
def test_execute_http_11_keep_forces_close(self):
inst = self._makeOne()
inst.version = "1.1"
inst.request.headers["CONNECTION"] = "keep-alive"
... |
def test_one_linefeed(self):
self.assertEqual(self._callFUT(b"\n"), -1)
def test_double_linefeed(self):
self.assertEqual(self._callFUT(b"\n\n"), 2)
def test_one_crlf(self):
self.assertEqual(self._callFUT(b"\r\n"), -1) | def test_one_linefeed(self):
self.assertEqual(self._callFUT(b"\n"), -1)
def test_double_linefeed(self):
self.assertEqual(self._callFUT(b"\n\n"), -1)
def test_one_crlf(self):
self.assertEqual(self._callFUT(b"\r\n"), -1) |
def test_double_crfl(self):
self.assertEqual(self._callFUT(b"\r\n\r\n"), 4)
def test_mixed(self):
self.assertEqual(self._callFUT(b"\n\n00\r\n\r\n"), 2)
class TestBadRequest(unittest.TestCase): | def test_double_crfl(self):
self.assertEqual(self._callFUT(b"\r\n\r\n"), 4)
def test_mixed(self):
self.assertEqual(self._callFUT(b"\n\n00\r\n\r\n"), 8)
class TestBadRequest(unittest.TestCase): |
def find_double_newline(s):
"""Returns the position just after a double newline in the given string."""
pos1 = s.find(b"\n\r\n") # One kind of double newline
if pos1 >= 0:
pos1 += 3
pos2 = s.find(b"\n\n") # Another kind of double newline
if pos2 >= 0:
pos2 += 2
if pos1 >= 0:
... |
def find_double_newline(s):
"""Returns the position just after a double newline in the given string."""
pos = s.find(b"\r\n\r\n")
if pos >= 0:
pos += 4
return pos
def concat(*args): |
def cleanup_unix_socket(path):
class Error(object):
def __init__(self, body):
self.body = body
| def cleanup_unix_socket(path):
class Error(object):
code = 500
reason = "Internal Server Error"
def __init__(self, body):
self.body = body
|
def to_response(self):
tag = "\r\n\r\n(generated by waitress)"
body = body + tag
headers = [("Content-Type", "text/plain")]
return status, headers, body
def wsgi_response(self, environ, start_response): | def to_response(self):
tag = "\r\n\r\n(generated by waitress)"
body = body + tag
headers = [("Content-Type", "text/plain")]
return status, headers, body
def wsgi_response(self, environ, start_response): |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.