示例#1
0
def checkContentTypeIgnoreCase(request, expectedContentType):
    """Performs Content-Type validation of the incoming request, ignoring case
    and any <code>charset</code> parameter.

    @see   #checkCharacterEncodingIgnoreCase(HttpServletRequest, String)
    @param request the incoming request
    @param expectedContentType the expected Content-Type for the incoming
           request
    @throws ServletException if the request's content type is not
            <code>null</code> and does not, ignoring case, equal
            <code>expectedContentType</code>,
    """
    assert expectedContentType is not None
    contentType = CONTENT_TYPE(request.environ())
    contentTypeIsOkay = False
    if contentType is not None:
        contentType = contentType.lower()
        # NOTE:We use startsWith because some servlet engines, do
        # not remove the charset component but others do.
        if contentType.startswith(expectedContentType.lower()):
            contentTypeIsOkay = True
    if not contentTypeIsOkay:
        raise ServletException('Content-Type was \'' + (
            '(null)' if contentType is None else contentType) +
                               '\'. Expected \'' + expectedContentType + '\'.')
示例#2
0
def checkContentTypeIgnoreCase(request, expectedContentType):
    """Performs Content-Type validation of the incoming request, ignoring case
    and any <code>charset</code> parameter.

    @see   #checkCharacterEncodingIgnoreCase(HttpServletRequest, String)
    @param request the incoming request
    @param expectedContentType the expected Content-Type for the incoming
           request
    @throws ServletException if the request's content type is not
            <code>null</code> and does not, ignoring case, equal
            <code>expectedContentType</code>,
    """
    assert expectedContentType is not None
    contentType = CONTENT_TYPE(request.environ())
    contentTypeIsOkay = False
    if contentType is not None:
        contentType = contentType.lower()
        # NOTE:We use startsWith because some servlet engines, do
        # not remove the charset component but others do.
        if contentType.startswith(expectedContentType.lower()):
            contentTypeIsOkay = True
    if not contentTypeIsOkay:
        raise ServletException('Content-Type was \''
                + ('(null)' if contentType is None else contentType)
                + '\'. Expected \'' + expectedContentType + '\'.')
示例#3
0
 def challenge(self, environ, status, app_headers, forget_headers):
     log.debug ("APP CHALLENGE %s %s %s %s", environ.keys(), status, app_headers, forget_headers)
     content_type = CONTENT_TYPE(environ)
     log.debug ("APP CONTENT %s", content_type)
     if any (content_type.startswith(v) for v in ('application/json', 'application/xml')):
         return  Response(status=401, content_type=content_type, body="")
     return None
示例#4
0
def bisque_request_classifier(environ):
    request_method = REQUEST_METHOD(environ)
    content_type = CONTENT_TYPE(environ)
    if request_method == "POST" and content_type.startswith(
            "application/json"):
        return "json"
    if content_type.startswith("application/xml"):
        return "xml"
    return default_request_classifier(environ)
示例#5
0
文件: basic.py 项目: bjornua/dna
 def auth_form(environ, start_response):
     towrite = "Challenging this"
     content_length = CONTENT_LENGTH.tuples(str(len(towrite)))
     content_type = CONTENT_TYPE.tuples('text/html')
     headers = content_length + content_type + forget_headers
     start_response('200 OK', headers)
     return [towrite]
示例#6
0
 def auth_form(environ, start_response):
     towrite = "Challenging this"
     content_length = CONTENT_LENGTH.tuples(str(len(towrite)))
     content_type = CONTENT_TYPE.tuples('text/html')
     headers = content_length + content_type + forget_headers
     start_response('200 OK', headers)
     return [towrite]
示例#7
0
def my_request_classifier(environ):
    """ Returns one of the classifiers 'dav', 'xmlpost', or 'browser',
    depending on the imperative logic below"""
    request_method = REQUEST_METHOD(environ)
    if request_method in _DAV_METHODS:
        return 'dav'
    useragent = USER_AGENT(environ)
    if useragent:
        for agent in _DAV_USERAGENTS:
            if useragent.find(agent) != -1:
                return 'dav'
    if request_method == 'POST':
        if CONTENT_TYPE(environ) == 'text/xml':
            return 'xmlpost'
        elif CONTENT_TYPE(environ) == "application/soap+xml":
            return 'soap'
    return 'browser'
示例#8
0
def bungeni_request_classifier(environ):
    """ Returns one of the classifiers "api", "xmlpost", or "browser",
    depending on the imperative logic below"""
    if PATH_INFO(environ).startswith("/api"):
        return "api"
    request_method = REQUEST_METHOD(environ)
    if request_method == "POST":
        if CONTENT_TYPE(environ) == "text/xml":
            return "xmlpost"
    return "browser"
示例#9
0
文件: who.py 项目: gelie/bungeni_src
def bungeni_request_classifier(environ):
    """ Returns one of the classifiers 'api', 'xmlpost', or 'browser',
    depending on the imperative logic below"""
    if PATH_INFO(environ).startswith("/api"):
        return 'api'
    request_method = REQUEST_METHOD(environ)
    if request_method == 'POST':
        if CONTENT_TYPE(environ) == 'text/xml':
            return 'xmlpost'
    return 'browser'
示例#10
0
文件: basic.py 项目: bjornua/dna
            def auth_resp(environ, start_response):
                import json
                resp = {"success": True}

                resp_str = json.dumps(resp)

                content_length = CONTENT_LENGTH.tuples(str(len(resp_str)))
                content_type = CONTENT_TYPE.tuples('application/json')
                headers = content_length + content_type
                start_response('200 OK', headers)
                return [resp_str]
示例#11
0
    def identify(self, environ):
        request = Request(environ)

        # first test for logout as we then don't need the rest
        if request.path == self.logout_path:
            headers = self.forget(environ, {})
            raise HTTPFound (location="/", headers = headers)

        if request.path == self.login_path:
            content_type = CONTENT_TYPE(environ)
            if content_type.startswith('application/json'):
                login_data = json.load (request.body_file)
            elif content_type.startswith('application/xml'):
                xml = etree.parse (request.body_file).getroot()
                login_data = dict (username = xml.find ("tag[@name='username']").get('value'),
                                   password = xml.find ("tag[@name='password']").get('value'))
            else:
                return None
            log.debug ("found user %s", login_data.get('username', None))
            return { 'login': login_data.get('username', None), 'password': login_data.get('password', None) }
        return None
示例#12
0
            def auth_resp(environ, start_response):
                import json
                resp = {
                    "success": True
                }

                resp_str = json.dumps(resp)

                content_length = CONTENT_LENGTH.tuples(str(len(resp_str)))
                content_type = CONTENT_TYPE.tuples('application/json')
                headers = content_length + content_type
                start_response('200 OK', headers)
                return [resp_str]
示例#13
0
 def auth_form(environ, start_response):
     content_length = CONTENT_LENGTH.tuples(str(len(form)))
     content_type = CONTENT_TYPE.tuples('text/html')
     headers = content_length + content_type + forget_headers
     start_response('200 OK', headers)
     return [form]
示例#14
0
 def getContentType(self, request):
     return CONTENT_TYPE(request.environ())