Ejemplo n.º 1
0
    def GenerateWelcomeFileHandlers(self):
        """Creates handlers for welcome files."""
        if not self.welcome_properties:
            return []

        return [
            handler.SimpleHandler('/', self.welcome_properties),
            handler.SimpleHandler('/*/', self.welcome_properties)
        ]
Ejemplo n.º 2
0
 def GenerateOrderedHandlerList(self):
     handler_patterns = (self.MakeServletPatternsIntoHandlers() +
                         self.GenerateSecurityConstraintHandlers() +
                         self.GenerateWelcomeFileHandlers())
     ordered_handlers = handler.GetOrderedIntersection(handler_patterns)
     if self.has_api_endpoint:
         ordered_handlers.append(
             handler.SimpleHandler(API_ENDPOINT_REGEX, {'type': 'dynamic'}))
     return ordered_handlers
 def MakeStaticUrlsIntoHandlers(self):
   handler_patterns = []
   for url, include in self.static_urls:
     properties = {'type': 'static'}
     if include.expiration:
       properties['expiration'] = include.expiration
     if include.http_headers:
       properties['http_headers'] = tuple(sorted(include.http_headers.items()))
     handler_patterns.append(handler.SimpleHandler(url, properties))
   return handler_patterns
  def MakeStaticFilePatternsIntoHandlers(self):
    """Creates SimpleHandlers out of XML-specified static file includes."""
    includes = self.static_file_includes
    if not includes:
      return [handler.SimpleHandler('/*', {'type': 'static'})]

    handler_patterns = []

    for include in includes:
      pattern = include.pattern.replace('**', '*')
      if pattern[0] != '/':
        pattern = '/' + pattern
      properties = {'type': 'static'}
      if include.expiration:
        properties['expiration'] = include.expiration
      if include.http_headers:

        properties['http_headers'] = tuple(sorted(include.http_headers.items()))
      handler_patterns.append(handler.SimpleHandler(pattern, properties))
    return handler_patterns
 def GenerateSecurityConstraintHandlers(self):
   """Creates Handlers for security constraint information."""
   handler_list = []
   for constraint in self.web_xml.security_constraints:
     props = {'transport_guarantee': constraint.transport_guarantee,
              'required_role': constraint.required_role}
     for pattern in constraint.patterns:
       security_handler = handler.SimpleHandler(pattern, props)
       handler_list.append(security_handler)
       handler_list += self.CreateHandlerWithoutTrailingStar(security_handler)
   return handler_list
  def MakeServletPatternsIntoHandlers(self):
    """Creates SimpleHandlers from servlet and filter mappings in web.xml."""
    handler_patterns = []
    has_jsps = self.has_jsps
    if self.fall_through:
      return [handler.SimpleHandler('/*', {'type': 'dynamic'})]

    for pattern in self.patterns:
      if pattern.endswith('.jsp'):
        has_jsps = True
      else:
        new_handler = handler.SimpleHandler(pattern, {'type': 'dynamic'})
        handler_patterns.append(new_handler)
        handler_patterns += self.CreateHandlerWithoutTrailingStar(new_handler)

    if has_jsps or self.app_engine_web_xml.vm:
      handler_patterns.append(
          handler.SimpleHandler('*.jsp', {'type': 'dynamic'}))

    handler_patterns.append(
        handler.SimpleHandler('/_ah/*', {'type': 'dynamic'}))
    return handler_patterns
Ejemplo n.º 7
0
    def CreateHandlerWithoutTrailingStar(self, h):
        """Creates identical handler without trailing star in pattern.

    According to servlet spec, baz/* should match baz.

    Args:
      h: a Handler.
    Returns:
      If h.pattern is of form "baz/*", returns a singleton list with a
      SimpleHandler with pattern "baz" and the properties of h. Otherwise,
      returns an empty list.
    """
        if len(h.pattern) <= 2 or h.pattern[-2:] != '/*':
            return []
        return [handler.SimpleHandler(h.pattern[:-2], h.properties)]