https ssl redir program program?

30 views
Skip to first unread message

bruce lee

unread,
Mar 24, 2017, 3:11:06 AM3/24/17
to Google App Engine
i am newbie......
i make program...redir https.....eveyone thing success.
After the client accesses, a large amount of time_wait is generated.
please help me?

code:
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://my.ip:443"+sub_url
            else:
                url = "http://my.ip"+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)


Adam (Cloud Platform Support)

unread,
Mar 24, 2017, 7:11:24 PM3/24/17
to Google App Engine
Posting your entire uncommented code and asking the community to debug it for you isn't likely to result in much feedback. If you can narrow it down to a specific succinct question I'd recommend posting a question to Stack Overflow. It's a good idea to first read the guide 'How do I ask a good question?' before posting.

If all you need to do is ensure some of your app's handlers are secured by HTTPS via redirect, you can do this with the 'secure: always' element in your app.yaml configuration.
Reply all
Reply to author
Forward
0 new messages