[Twisted-web] newclient.py cookies and POST
Jeff Pitman
twisted-web@twistedmatrix.com
Sun, 28 Dec 2003 00:00:52 -0800 (PST)
The following patch fixes cookies and POST requests for
Quotient/quotient/web/newclient.py (diff'd against latest CVS). I
gracefully stole from twisted/web/client.py because the original
attempt didn't work for more than one cookie on newclient.py.
Enjoy it,
jeff
--- Quotient/quotient/web/newclient.py 2003-12-28
15:03:35.000000000 +0800
+++ newclient.py 2003-12-28 15:18:02.000000000 +0800
@@ -103,7 +103,7 @@
def sendHeaders(connection, req):
if req.has_data():
data = req.get_data()
- connection.sendCommand('POST', requ.get_selector())
+ connection.sendCommand('POST', req.get_selector())
if not req.headers.has_key('Content-type'):
connection.sendHeader('Content-type',
'application/x-www-form-urlencoded')
@@ -146,8 +146,11 @@
factory = ClientFactory(self.cookies)
self.callMethod('connect_'+request.get_type(), request,
factory)
d = factory.connection
- for cookie in self.cookies:
- request.add_header("Cookie", '='.join([cookie,
self.cookies[cookie]]))
+ if self.cookies:
+ l=[]
+ for cookie, cookval in self.cookies.items():
+ l.append('%s=%s' % (cookie, cookval))
+ request.add_header("Cookie", "; ".join(l))
request.add_header('Referer', self.referrer)
self.referrer = request.get_full_url()
d.addCallback(sendHeaders, request)
__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree