Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1689

Show
Ignore:
Timestamp:
06/24/07 00:16:23
Author:
fumanchu
Message:

Fixes to cpmodpy to allow streaming and guarantee running on_end_request hooks.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/_cpmodpy.py

    r1685 r1689  
    169169            prev = None 
    170170             
    171             redirections = [] 
    172             while True: 
    173                 request, response = app.get_serving(local, remote, scheme, 
    174                                                     "HTTP/1.1") 
    175                 request.login = req.user 
    176                 request.multithread = bool(threaded) 
    177                 request.multiprocess = bool(forked) 
    178                 request.app = app 
    179                 request.prev = prev 
     171            try: 
     172                redirections = [] 
     173                while True: 
     174                    request, response = app.get_serving(local, remote, scheme, 
     175                                                        "HTTP/1.1") 
     176                    request.login = req.user 
     177                    request.multithread = bool(threaded) 
     178                    request.multiprocess = bool(forked) 
     179                    request.app = app 
     180                    request.prev = prev 
     181                     
     182                    # Run the CherryPy Request object and obtain the response 
     183                    try: 
     184                        request.run(method, path, qs, reqproto, headers, rfile) 
     185                        break 
     186                    except cherrypy.InternalRedirect, ir: 
     187                        app.release_serving() 
     188                        prev = request 
     189                         
     190                        if not recursive: 
     191                            if ir.path in redirections: 
     192                                raise RuntimeError("InternalRedirector visited the " 
     193                                                   "same URL twice: %r" % ir.path) 
     194                            else: 
     195                                # Add the *previous* path_info + qs to redirections. 
     196                                if qs: 
     197                                    qs = "?" + qs 
     198                                redirections.append(sn + path + qs) 
     199                         
     200                        # Munge environment and try again. 
     201                        method = "GET" 
     202                        path = ir.path 
     203                        qs = ir.query_string 
     204                        rfile = StringIO.StringIO() 
    180205                 
    181                 # Run the CherryPy Request object and obtain the response 
    182                 try: 
    183                     request.run(method, path, qs, reqproto, headers, rfile) 
    184                     break 
    185                 except cherrypy.InternalRedirect, ir: 
    186                     app.release_serving() 
    187                     prev = request 
    188                      
    189                     if not recursive: 
    190                         if ir.path in redirections: 
    191                             raise RuntimeError("InternalRedirector visited the " 
    192                                                "same URL twice: %r" % ir.path) 
    193                         else: 
    194                             # Add the *previous* path_info + qs to redirections. 
    195                             if qs: 
    196                                 qs = "?" + qs 
    197                             redirections.append(sn + path + qs) 
    198                      
    199                     # Munge environment and try again. 
    200                     method = "GET" 
    201                     path = ir.path 
    202                     qs = ir.query_string 
    203                     rfile = StringIO.StringIO() 
    204              
    205             send_response(req, response.status, response.header_list, response.body) 
    206             app.release_serving() 
     206                send_response(req, response.status, response.header_list, 
     207                              response.body, response.stream) 
     208            finally: 
     209                app.release_serving() 
    207210    except: 
    208211        tb = format_exc() 
     
    212215    return apache.OK 
    213216 
    214 def send_response(req, status, headers, body): 
     217 
     218def send_response(req, status, headers, body, stream=False): 
    215219    # Set response status 
    216220    req.status = int(status[:3]) 
     
    223227            continue 
    224228        req.headers_out.add(header, value) 
     229     
     230    if stream: 
     231        # Flush now so the status and headers are sent immediately. 
     232        req.flush() 
    225233     
    226234    # Set response body 

Hosted by WebFaction

Log in as guest/cpguest to create tickets