Revision 358a8811 lib/http/__init__.py
b/lib/http/__init__.py | ||
---|---|---|
151 | 151 |
@type poller: select.Poller |
152 | 152 |
@param poller: Poller object as created by select.poll() |
153 | 153 |
@type sock: socket |
154 |
@param socket: Wait for events on this socket
|
|
154 |
@param sock: Wait for events on this socket |
|
155 | 155 |
@type event: int |
156 | 156 |
@param event: ORed condition (see select module) |
157 | 157 |
@type timeout: float or None |
... | ... | |
193 | 193 |
@type poller: select.Poller |
194 | 194 |
@param poller: Poller object as created by select.poll() |
195 | 195 |
@type sock: socket |
196 |
@param socket: Socket for the operation
|
|
196 |
@param sock: Socket for the operation |
|
197 | 197 |
@type op: int |
198 | 198 |
@param op: Operation to execute (SOCKOP_* constants) |
199 | 199 |
@type arg1: any |
200 | 200 |
@param arg1: Parameter for function (if needed) |
201 | 201 |
@type timeout: None or float |
202 | 202 |
@param timeout: Timeout in seconds or None |
203 |
@return: Return value of socket function |
|
203 | 204 |
|
204 | 205 |
""" |
205 | 206 |
# TODO: event_poll/event_check/override |
... | ... | |
304 | 305 |
force): |
305 | 306 |
"""Closes the connection. |
306 | 307 |
|
308 |
@type poller: select.Poller |
|
309 |
@param poller: Poller object as created by select.poll() |
|
310 |
@type sock: socket |
|
311 |
@param sock: Socket to be shut down |
|
312 |
@type close_timeout: float |
|
313 |
@param close_timeout: How long to wait for the peer to close the connection |
|
314 |
@type write_timeout: float |
|
315 |
@param write_timeout: Write timeout for shutdown |
|
316 |
@type msgreader: http.HttpMessageReader |
|
317 |
@param msgreader: Request message reader, used to determine whether peer |
|
318 |
should close connection |
|
319 |
@type force: bool |
|
320 |
@param force: Whether to forcibly close the connection without waiting |
|
321 |
for peer |
|
322 |
|
|
307 | 323 |
""" |
308 | 324 |
poller = select.poll() |
309 | 325 |
|
... | ... | |
455 | 471 |
|
456 | 472 |
""" |
457 | 473 |
def __init__(self, sock, msg, write_timeout): |
474 |
"""Initializes this class and writes an HTTP message to a socket. |
|
475 |
|
|
476 |
@type sock: socket |
|
477 |
@param sock: Socket to be written to |
|
478 |
@type msg: http.HttpMessage |
|
479 |
@param msg: HTTP message to be written |
|
480 |
@type write_timeout: float |
|
481 |
@param write_timeout: Write timeout for socket |
|
482 |
|
|
483 |
""" |
|
458 | 484 |
self._msg = msg |
459 | 485 |
|
460 | 486 |
self._PrepareMessage() |
... | ... | |
467 | 493 |
end = len(buf) |
468 | 494 |
while pos < end: |
469 | 495 |
# Send only SOCK_BUF_SIZE bytes at a time |
470 |
data = buf[pos:pos+SOCK_BUF_SIZE]
|
|
496 |
data = buf[pos:(pos + SOCK_BUF_SIZE)]
|
|
471 | 497 |
|
472 | 498 |
sent = SocketOperation(poller, sock, SOCKOP_SEND, data, |
473 | 499 |
write_timeout) |
... | ... | |
537 | 563 |
PS_COMPLETE = "complete" |
538 | 564 |
|
539 | 565 |
def __init__(self, sock, msg, read_timeout): |
566 |
"""Reads an HTTP message from a socket. |
|
567 |
|
|
568 |
@type sock: socket |
|
569 |
@param sock: Socket to be read from |
|
570 |
@type msg: http.HttpMessage |
|
571 |
@param msg: Object for the read message |
|
572 |
@type read_timeout: float |
|
573 |
@param read_timeout: Read timeout for socket |
|
574 |
|
|
575 |
""" |
|
540 | 576 |
self.sock = sock |
541 | 577 |
self.msg = msg |
542 | 578 |
|
... | ... | |
608 | 644 |
# beginning of a message and receives a CRLF first, it should ignore |
609 | 645 |
# the CRLF." |
610 | 646 |
if idx == 0: |
611 |
# TODO: Limit number of CRLFs for safety? |
|
647 |
# TODO: Limit number of CRLFs/empty lines for safety?
|
|
612 | 648 |
buf = buf[:2] |
613 | 649 |
continue |
614 | 650 |
|
Also available in: Unified diff