# Copyright (C) 2018 The Android Open Source Project
#
# 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.

from google.appengine.api import memcache
from google.appengine.api import urlfetch

import re
import webapp2

MEMCACHE_TTL_SEC = 60 * 60 * 24
BASE = 'https://catapult-project.github.io/perfetto/%s'
HEADERS = {
    'last-modified', 'content-type', 'content-length', 'content-encoding',
    'etag'
}


class MainHandler(webapp2.RequestHandler):

  def get(self):
    handler = GithubMirrorHandler()
    handler.initialize(self.request, self.response)
    return handler.get("index.html")


class GithubMirrorHandler(webapp2.RequestHandler):

  def get(self, resource):
    if not re.match('^[a-zA-Z0-9-_./]*$', resource):
      self.response.set_status(403)
      return

    url = BASE % resource
    cache = memcache.get(url)
    if not cache or self.request.get('reload'):
      result = urlfetch.fetch(url)
      if result.status_code != 200:
        memcache.delete(url)
        self.response.set_status(result.status_code)
        self.response.write(result.content)
        return
      cache = {'content-type': 'text/html'}
      for k, v in result.headers.iteritems():
        k = k.lower()
        if k in HEADERS:
          cache[k] = v
      cache['content'] = result.content
      memcache.set(url, cache, time=MEMCACHE_TTL_SEC)

    for k, v in cache.iteritems():
      if k != 'content':
        self.response.headers[k] = v
    self.response.headers['cache-control'] = 'public,max-age=600'
    self.response.write(cache['content'])


app = webapp2.WSGIApplication([
    ('/', MainHandler),
    ('/(.+)', GithubMirrorHandler),
],
                              debug=True)
