Skip to content

Instantly share code, notes, and snippets.

@dahlia
Last active December 13, 2015 20:29
Show Gist options
  • Save dahlia/4970516 to your computer and use it in GitHub Desktop.
Save dahlia/4970516 to your computer and use it in GitHub Desktop.
This is a simple proxy web app that makes POST requests by requesting GET payloads to this.
.*.swp
*.pyc

GET to POST

This is a simple proxy web app that makes POST requests by requesting GET payloads to this.

application: simple-get2post
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: .*
script: get2post.app
libraries:
- name: webapp2
version: "2.5.2"
import urllib
from google.appengine.api.urlfetch import fetch
from webapp2 import RequestHandler, WSGIApplication
class TransferHandler(RequestHandler):
def get(self, scheme, url):
url = '{0}://{1}'.format(scheme, url)
query = {}
data = {}
for key, value in self.request.GET.items():
if key.startswith('get.'):
query[key[4:]] = value
elif key.startswith('post.'):
data[key[5:]] = value
if query:
url += '?' + urllib.urlencode(query)
payload = urllib.urlencode(data)
response = fetch(url, payload=payload, method='POST')
self.response.status_int = response.status_code
for header, value in response.headers.items():
self.response.headers[header] = value
self.response.write(response.content)
app = WSGIApplication([
('/(?P<scheme>https?)/(?P<url>.+)', TransferHandler)
], debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment