etwist/server.py
changeset 5940 0e3ae19b181a
parent 5933 3d707b8f8a4d
child 6778 7dd4835d5198
equal deleted inserted replaced
5939:a33402c1aa79 5940:0e3ae19b181a
    36 from twisted.internet.defer import maybeDeferred
    36 from twisted.internet.defer import maybeDeferred
    37 from twisted.web import http, server
    37 from twisted.web import http, server
    38 from twisted.web import static, resource
    38 from twisted.web import static, resource
    39 from twisted.web.server import NOT_DONE_YET
    39 from twisted.web.server import NOT_DONE_YET
    40 
    40 
    41 from cubicweb.web import dumps
       
    42 
    41 
    43 from logilab.common.decorators import monkeypatch
    42 from logilab.common.decorators import monkeypatch
    44 
    43 
    45 from cubicweb import AuthenticationError, ConfigurationError, CW_EVENT_MANAGER
    44 from cubicweb import AuthenticationError, ConfigurationError, CW_EVENT_MANAGER
       
    45 from cubicweb.utils import json_dumps
    46 from cubicweb.web import Redirect, DirectResponse, StatusResponse, LogOut
    46 from cubicweb.web import Redirect, DirectResponse, StatusResponse, LogOut
    47 from cubicweb.web.application import CubicWebPublisher
    47 from cubicweb.web.application import CubicWebPublisher
    48 from cubicweb.web.http_headers import generateDateTime
    48 from cubicweb.web.http_headers import generateDateTime
    49 from cubicweb.etwist.request import CubicWebTwistedRequestAdapter
    49 from cubicweb.etwist.request import CubicWebTwistedRequestAdapter
    50 from cubicweb.etwist.http import HTTPResponse
    50 from cubicweb.etwist.http import HTTPResponse
   315         self.clientproto = 'HTTP/1.1' # not yet initialized
   315         self.clientproto = 'HTTP/1.1' # not yet initialized
   316         self.channel.persistent = 0   # force connection close on cleanup
   316         self.channel.persistent = 0   # force connection close on cleanup
   317         self.setResponseCode(http.BAD_REQUEST)
   317         self.setResponseCode(http.BAD_REQUEST)
   318         if path in JSON_PATHS: # XXX better json path detection
   318         if path in JSON_PATHS: # XXX better json path detection
   319             self.setHeader('content-type',"application/json")
   319             self.setHeader('content-type',"application/json")
   320             body = dumps({'reason': 'request max size exceeded'})
   320             body = json_dumps({'reason': 'request max size exceeded'})
   321         elif path in FRAME_POST_PATHS: # XXX better frame post path detection
   321         elif path in FRAME_POST_PATHS: # XXX better frame post path detection
   322             self.setHeader('content-type',"text/html")
   322             self.setHeader('content-type',"text/html")
   323             body = ('<script type="text/javascript">'
   323             body = ('<script type="text/javascript">'
   324                     'window.parent.handleFormValidationResponse(null, null, null, %s, null);'
   324                     'window.parent.handleFormValidationResponse(null, null, null, %s, null);'
   325                     '</script>' % dumps( (False, 'request max size exceeded', None) ))
   325                     '</script>' % json_dumps( (False, 'request max size exceeded', None) ))
   326         else:
   326         else:
   327             self.setHeader('content-type',"text/html")
   327             self.setHeader('content-type',"text/html")
   328             body = ("<html><head><title>Processing Failed</title></head><body>"
   328             body = ("<html><head><title>Processing Failed</title></head><body>"
   329                     "<b>request max size exceeded</b></body></html>")
   329                     "<b>request max size exceeded</b></body></html>")
   330         self.setHeader('content-length', str(len(body)))
   330         self.setHeader('content-length', str(len(body)))