|
67 | 67 | prefer to see your error codes, then do. |
68 | 68 |
|
69 | 69 | """ |
| 70 | +from httplib import _CS_REQ_STARTED, _CS_REQ_SENT, CannotSendHeader |
70 | 71 |
|
71 | 72 | import threading |
72 | 73 | import urllib2 |
@@ -113,6 +114,7 @@ def _get_connection_key(self, host): |
113 | 114 | return (threading.currentThread(), host) |
114 | 115 |
|
115 | 116 | def _start_connection(self, h, req): |
| 117 | + h.clearheaders() |
116 | 118 | try: |
117 | 119 | if req.has_data(): |
118 | 120 | data = req.get_data() |
@@ -289,7 +291,37 @@ def readlines(self, sizehint = 0): |
289 | 291 | class HTTPConnection(httplib.HTTPConnection): |
290 | 292 | # use the modified response class |
291 | 293 | response_class = HTTPResponse |
292 | | - |
| 294 | + _headers = {} |
| 295 | + |
| 296 | + def clearheaders(self): |
| 297 | + self._headers.clear() |
| 298 | + |
| 299 | + def putheader(self, header, value): |
| 300 | + """Send a request header line to the server. |
| 301 | +
|
| 302 | + For example: h.putheader('Accept', 'text/html') |
| 303 | + """ |
| 304 | + if self.__state != _CS_REQ_STARTED: |
| 305 | + raise CannotSendHeader() |
| 306 | + |
| 307 | + self._headers[header] = value |
| 308 | + |
| 309 | + |
| 310 | + def endheaders(self): |
| 311 | + """Indicate that the last header line has been sent to the server.""" |
| 312 | + |
| 313 | + if self.__state == _CS_REQ_STARTED: |
| 314 | + self.__state = _CS_REQ_SENT |
| 315 | + else: |
| 316 | + raise CannotSendHeader() |
| 317 | + |
| 318 | + for header, value in self._headers.items(): |
| 319 | + print header, value |
| 320 | + str = '%s: %s' % (header, value) |
| 321 | + self._output(str) |
| 322 | + |
| 323 | + self._send_output() |
| 324 | + |
293 | 325 | ######################################################################### |
294 | 326 | ##### TEST FUNCTIONS |
295 | 327 | ######################################################################### |
|
0 commit comments