Skip to content

Commit

Permalink
refine pagespeed
Browse files Browse the repository at this point in the history
  • Loading branch information
phuslu committed Jun 9, 2014
1 parent 4f478b8 commit 5bc60f8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions local/proxy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ profile = ipv4
window = 12
keepalive = 0
obfuscate = 0
pagespeed = 0
validate = 0
transport = 0
options =
Expand Down
5 changes: 3 additions & 2 deletions local/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,9 +782,10 @@ def __gae_fetch(self, method, url, headers, body, timeout, **kwargs):
request_headers = {}
if common.GAE_OBFUSCATE:
request_method = 'GET'
ps_header = base64.b64encode(deflate(metadata + '\n' + (body or ''))).strip()
request_headers['X-GOA-PS'] = ps_header
request_fetchserver += '/ps/%s.gif' % uuid.uuid1()
request_headers['X-GOA-PS1'] = base64.b64encode(deflate(metadata)).strip()
if body:
request_headers['X-GOA-PS2'] = base64.b64encode(deflate(body)).strip()
if common.GAE_PAGESPEED:
request_fetchserver = re.sub(r'^(\w+://)', r'\g<1>1-ps.googleusercontent.com/h/', request_fetchserver)
else:
Expand Down
2 changes: 1 addition & 1 deletion server/gae/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ handlers:
script: gae.application
secure: optional

- url: /2
- url: /2.*
script: gae.application
secure: optional

Expand Down
12 changes: 7 additions & 5 deletions server/gae/gae.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ def deflate(data):


def application(environ, start_response):
ps_header = environ.get('HTTP_X_GOA_PS', '')
# logging.info('ps_header=%r', ps_header)
ps_headers = dict((x, environ[x]) for x in environ if x.startswith('HTTP_X_GOA_PS'))
# logging.info('ps_headers=%r', ps_headers)
options = environ.get('HTTP_X_GOA_OPTIONS', '')

if environ['REQUEST_METHOD'] == 'GET' and not ps_header:
if environ['REQUEST_METHOD'] == 'GET' and not ps_headers:
timestamp = long(os.environ['CURRENT_VERSION_ID'].split('.')[1])/2**28
ctime = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(timestamp+8*3600))
html = u'GoAgent Python Server %s \u5df2\u7ecf\u5728\u5de5\u4f5c\u4e86\uff0c\u90e8\u7f72\u65f6\u95f4 %s\n' % (__version__, ctime)
Expand All @@ -116,8 +116,9 @@ def application(environ, start_response):
raise StopIteration

try:
if ps_header:
metadata, payload = inflate(base64.b64decode(ps_header)).split('\n\n', 1)
if ps_headers:
metadata = inflate(base64.b64decode(ps_headers['HTTP_X_GOA_PS1']))
payload = inflate(base64.b64decode(ps_headers['HTTP_X_GOA_PS2'])) if 'HTTP_X_GOA_PS2' in ps_headers else ''
else:
wsgi_input = environ['wsgi.input']
input_data = wsgi_input.read(int(environ.get('CONTENT_LENGTH', '0')))
Expand Down Expand Up @@ -256,6 +257,7 @@ def application(environ, start_response):
yield RC4Cipher(__password__).encrypt(response_headers_data)
yield RC4Cipher(__password__).encrypt(data)


class LegacyHandler(object):
"""GoAgent 1.x GAE Fetch Server"""
@classmethod
Expand Down

0 comments on commit 5bc60f8

Please sign in to comment.