Skip to content
Browse files

- Fetch POST data via task

  • Loading branch information...
1 parent d31dec6 commit d79919bc59bfbe6c2f92936fd6497e583703dc4d @superisaac committed Jan 28, 2010
Showing with 11 additions and 2 deletions.
  1. +11 −2 redqueue/task.py
View
13 redqueue/task.py
@@ -1,6 +1,8 @@
import random
import time
import logging
+import urllib
+
try:
import json
except ImportError:
@@ -52,10 +54,12 @@ def on_data(self, data):
if isinstance(data, basestring):
url = data
delay = 0
+ method = 'GET'
else: # data should be a dictionary
url = data['url']
delay = data.get('delay', 0)
-
+ method = data.get('method', 'GET')
+
def handle_response(response):
if response.error:
logging.error('Error %s while fetch url %s' % (response.error,
@@ -66,7 +70,12 @@ def handle_response(response):
def fetch_url(url):
logging.info('Fetching url %s' % url)
http_client = AsyncHTTPClient()
- http_client.fetch(url, handle_response)
+ if method == 'POST':
+ postdata = urllib.urlencode(data.get('body', {}))
+ else:
+ postdata = None
+ http_client.fetch(url, handle_response,
+ method=method, body=postdata)
if delay:
ioloop.IOLoop.instance().add_timeout(time.time() + delay,

0 comments on commit d79919b

Please sign in to comment.
Something went wrong with that request. Please try again.