1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import urlfetch
import urllib

class MainPage(webapp.RequestHandler):
  def get(self):
    url = self.request.get('url')
    callback = str(self.request.get('callback'))
    self.response.headers['Content-Type'] = 'text/html'
    try:
      urlObject = urlfetch.fetch(url, None, 'GET', {}, False, True)
      self.response.out.write(callback)
      self.response.out.write('(')
      self.response.out.write(urlObject.content)
      self.response.out.write(');')
    except:
      self.response.out.write(url)
    
application = webapp.WSGIApplication(
                                     [('/', MainPage)],
                                     debug=True)

def main():
  run_wsgi_app(application)

if __name__ == "__main__":
  main()