Edgewall Software

Ticket #8020: t8020-http11-r7956.2.diff

File t8020-http11-r7956.2.diff, 2.5 KB (added by cboos, 3 years ago)

Same as attachment:t8020-http11-r7956.diff but with reverse name lookups also disabled when specifying --http11

  • trac/web/standalone.py

     
    102102 
    103103class TracHTTPServer(ThreadingMixIn, WSGIServer): 
    104104 
    105     def __init__(self, server_address, application, env_parent_dir, env_paths): 
     105    def __init__(self, server_address, application, env_parent_dir, env_paths, 
     106                 use_http_11=False): 
     107        request_handlers = (TracHTTPRequestHandler, TracHTTP11RequestHandler) 
    106108        WSGIServer.__init__(self, server_address, application, 
    107                             request_handler=TracHTTPRequestHandler) 
     109                            request_handler=request_handlers[bool(use_http_11)]) 
    108110 
    109111 
    110112class TracHTTPRequestHandler(WSGIRequestHandler): 
     
    115117        # Disable reverse name lookups 
    116118        return self.client_address[:2][0] 
    117119 
     120class TracHTTP11RequestHandler(TracHTTPRequestHandler): 
     121    protocol_version = 'HTTP/1.1' 
    118122 
     123 
    119124def main(): 
    120125    from optparse import OptionParser, OptionValueError 
    121126    parser = OptionParser(usage='usage: %prog [options] [projenv] ...', 
     
    161166    parser.add_option('-q', '--unquote', action='store_true', 
    162167                      dest='unquote', 
    163168                      help='unquote PATH_INFO (may be needed when using ajp') 
     169    parser.add_option('--http11', action='store_true', dest='http11', 
     170                      help='use HTTP/1.1 protocol version instead of HTTP/1.0') 
    164171    parser.add_option('-e', '--env-parent-dir', action='store', 
    165172                      dest='env_parent_dir', metavar='PARENTDIR', 
    166173                      help='parent directory of the project environments') 
     
    237244    if options.protocol == 'http': 
    238245        def serve(): 
    239246            httpd = TracHTTPServer(server_address, wsgi_app, 
    240                                    options.env_parent_dir, args) 
     247                                   options.env_parent_dir, args, 
     248                                   use_http_11=options.http11) 
     249 
    241250            print 'Server starting in PID %i.' % os.getpid() 
    242251            addr, port = server_address 
    243252            if not addr or addr == '0.0.0.0': 
     
    245254                       % (port, port, base_path) 
    246255            else: 
    247256                print 'Serving on http://%s:%s/%s' % (addr, port, base_path) 
     257            if options.http11: 
     258                print 'Using HTTP/1.1 protocol version' 
    248259            httpd.serve_forever() 
    249260    elif options.protocol in ('scgi', 'ajp'): 
    250261        def serve():