1. artgins
  2. ginsfsm

Commits

Ginés Martínez Sánchez  committed e78ceaf Draft

developing wsgi server

  • Participants
  • Parent commits cfb264f
  • Branches default

Comments (0)

Files changed (3)

File ginsfsm/protocols/http/server/c_http_clisrv.py

View file
 
 """
 from collections import deque
+import logging
+import traceback
 
 from ginsfsm.c_timer import GTimer
 from ginsfsm.gobj import GObj
 def ac_http_response(self, event):
     response = event.response
     self.stop_responseless_timer()
-    response.service()  # send response to client
     self.responding_request = None
 
+    try:
+        response.service()
+    except:
+        logging.exception('Exception when serving %s' % response.request.path)
+        if not response.wrote_header:
+            if self.expose_tracebacks:
+                body = traceback.format_exc()
+            else:
+                body = ('The server encountered an unexpected '
+                        'internal server error')
+
+            request = HTTPRequestParser(self)
+            request.error = InternalServerError(body)
+            response = HttpErrorResponse(request)
+            response.service()
+        else:
+            response.close_on_finish = True
+
     if response.close_on_finish:
         self.clear_request_queue()
         return

File ginsfsm/protocols/wsgi/common/wsgi_response.py

View file
     """
     environ = None
 
-    def __init__(self, request, wsgi_server, toclose=True):
+    def __init__(self, request, wsgi_server):
         HttpResponse.__init__(self, request)
         self.wsgi_server = wsgi_server
-        self.toclose = toclose
 
     def execute(self):
         env = self.get_environment()

File ginsfsm/protocols/wsgi/server/c_wsgi_server.py

View file
 
 """
 
-import logging
-import traceback
-
 from ginsfsm.gobj import GObj
-from ginsfsm.deferred import DeferredInterrupt
 from ginsfsm.protocols.http.server.c_http_server import GHttpServer
 from ginsfsm.protocols.wsgi.common.wsgi_response import WsgiResponse
 from ginsfsm.protocols.http.server.c_http_server import GHTTPSERVER_GCONFIG
-from ginsfsm.protocols.http.common.parser import HTTPRequestParser
-from ginsfsm.protocols.http.common.utilities import InternalServerError
-from ginsfsm.protocols.http.common.response import HttpErrorResponse
 
 
 def ac_channel_opened(self, event):
-    print "======> channel opened"
+    """ New client opened.
+    """
 
 
 def ac_channel_closed(self, event):
-    print "======> channel closed"
+    """ Client closed.
+    """
 
 
 def ac_request(self, event):
-    print "======> channel request"
     channel = event.source[-1]
     request = event.request
-    ext_event = None
-    response = WsgiResponse(
-        request,
-        'Caraculo\r\nCaraculo\r\nCaraculo\r\n'
-    )
+    response = WsgiResponse(request, self)
     self.send_event(channel, 'EV_HTTP_RESPONSE', response=response)
 
-    if hasattr(event, 'ext_event'):
-        ext_event = event.ext_event
-
-    # Añado esto en get_environment de task.py,despues de environ = {}
-    # environ['gobj.gsock'] = gsock
-    toclose = True
-    response = WsgiResponse(request, self, toclose)
-    try:
-        response.service()
-    except DeferredInterrupt as e:
-
-        def callback(request, ext_event=None):
-            self.send_event(
-                self,
-                'EV_EXECUTE_REQUESTS',
-                requests=[request],
-                ext_event=ext_event,
-            )
-        self.gaplic.deferred_list.add_callback(
-            e.deferred_ref,
-            callback,
-            request,
-            ext_event
-        )
-    except:
-        logging.exception('Exception when serving %s' % response.request.path)
-        if not response.wrote_header:
-            if self.expose_tracebacks:
-                body = traceback.format_exc()
-            else:
-                body = ('The server encountered an unexpected '
-                        'internal server error')
-
-            request = HTTPRequestParser(self)
-            request.error = InternalServerError(body)
-            response = HttpErrorResponse(request)
-            response.service()
-        else:
-            response.close_on_finish = True
-
 
 GWSGISERVER_FSM = {
     'event_list': (