I use GAE platform to forward HTTP SSL data.(python webapp2)
why?use ssl client make large time_wait connect?
But HTTP is normal.




code:


#!/usr/bin/env python
#
# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import base64, logging
import webapp2
from google.appengine.api import urlfetch

class MainHandler(webapp2.RequestHandler):
    def get(self):
        useSSL = 0
        _url = self.request.url.lower()
        if _url.find('https://')==0:
            useSSL = 1

        _url = self.request.url #restore
        
        _path = self.request.path
        
        if _path=="/": #for test
            self.response.headers["Content-Type"] = "text/html; 
charset=utf-8"
            self.response.write("Hello, guys")
        else:      
            nPos = _url.find(_path)    
            sub_url = _url[nPos:len(_url)]

            if useSSL==1:
                url = "https://198.52.119.103:443"+sub_url
            else:
                url = "http://198.52.119.103"+sub_url

            rpc = urlfetch.create_rpc()
            urlfetch.make_fetch_call(rpc, url, validate_certificate=False)


            # ... do other things ..
            try:
                result = rpc.get_result()
                if result.status_code == 200:
                    text = result.content
                    self.response.write(text)
                else:
                    self.response.status_int = result.status_code
                    self.response.write('URL returned status code 
{}'.format(result.status_code))
            except urlfetch.DownloadError:
                self.response.status = 500
                self.response.write('Error fetching URL')

    def post(self):
        useSSL = 0
        _url = self.request.url.lower()
        if _url.find('https://')==0:
            useSSL = 1

        _url = self.request.url #restore
        
        _path = self.request.path
        
        if _path=="/": #for test
            self.response.headers["Content-Type"] = "text/html; 
charset=utf-8"
            self.response.write("Hello, guys")
        else:      
            nPos = _url.find(_path)    
            sub_url = _url[nPos:len(_url)]
    

            if useSSL==1:
                url = "https://test.server.com:443"+sub_url
            else:
                url = "http://test.server.com"+sub_url

            
                #def make_fetch_call(rpc, url, payload=None, method=GET, 
headers={},
                #    allow_truncated=False, follow_redirects=True,
                #    validate_certificate=None):

            _headers = {'Content-Type': 'application/octet-stream', 
'Content-Length': self.request.headers['Content-Length']}
            rpc = urlfetch.create_rpc()
            urlfetch.make_fetch_call(rpc, url, self.request.body, 2, 
_headers, validate_certificate=False)


            # ... do other things ..
            try:
                result = rpc.get_result()
                if result.status_code == 200:
                    text = result.content
                    self.response.write(text)
                else:
                    self.response.status_int = result.status_code
                    self.response.write('URL returned status code 
{}'.format(result.status_code))
            except urlfetch.DownloadError:
                self.response.status = 500
                self.response.write('Error fetching URL')
      
app = webapp2.WSGIApplication([
    ('.*', MainHandler)
], debug=True)

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-appengine+unsubscr...@googlegroups.com.
To post to this group, send email to google-appengine@googlegroups.com.
Visit this group at https://groups.google.com/group/google-appengine.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-appengine/a9a4311a-7395-4775-a630-f2a7dc6c37b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
  • [google-appengine] w... bruce lee

Reply via email to