コード例 #1
0
 def testInsertHeaderNone(self):
     def handleRequest(*args, **kwargs):
         yield "HTTP/1.0 200 OK\r\n"
         yield "Header: value\r\n\r\n"
         yield '<ht'
         yield 'ml/>'
     self.assertEqual('HTTP/1.0 200 OK\r\nHeader: value\r\n\r\n<html/>', asString(utils.insertHeader(handleRequest(), None)))
コード例 #2
0
    def testInsertHeaderWithEmptyLines(self):
        def handleRequest(*args, **kwargs):
            yield "HTTP/1.0 200 OK\r\n"
            yield "Header: value\r\n\r\n"
            yield '<ht'
            yield 'ml/>'

        result = list(utils.insertHeader(handleRequest(), 'Set-Cookie: session=dummySessionId1234; path=/'))
        self.assertFalse('' in result, result)
コード例 #3
0
    def testInsertHeaderNone(self):
        def handleRequest(*args, **kwargs):
            yield "HTTP/1.0 200 OK\r\n"
            yield "Header: value\r\n\r\n"
            yield '<ht'
            yield 'ml/>'

        self.assertEqual('HTTP/1.0 200 OK\r\nHeader: value\r\n\r\n<html/>',
                         asString(utils.insertHeader(handleRequest(), None)))
コード例 #4
0
    def testInsertHeaderWithBytes(self):
        def handleRequest(*args, **kwargs):
            yield b"HTTP/1.0 200 OK\r\n"
            yield b"Header: value\r\n\r\n"
            yield '<ht'
            yield 'ml/>'

        result = list(
            utils.insertHeader(
                handleRequest(),
                'Set-Cookie: session=dummySessionId1234; path=/'))
コード例 #5
0
 def logout(self, session, Headers, **ignored):
     session.pop(USER, None)
     redirectUrl = self._home
     response = redirectHttp % redirectUrl
     if not self._rememberMeCookie:
         yield response
         return
     cookieName = self.call.cookieName()
     for cookie in findCookies(Headers=Headers, name=cookieName):
         self.call.removeCookie(cookie)
     yield insertHeader([response], 'Set-Cookie: {}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/'.format(cookieName))
コード例 #6
0
    def testInsertHeader(self):
        def handleRequest(*args, **kwargs):
            yield  utils.okHtml
            yield '<ht'
            yield 'ml/>'

        newHeader = 'Set-Cookie: session=dummySessionId1234; path=/'
        result = ''.join(utils.insertHeader(handleRequest(), newHeader))
        header, body = result.split(utils.CRLF*2, 1)
        self.assertEquals('<html/>', body)
        headerParts = header.split(utils.CRLF)
        self.assertEquals("HTTP/1.0 200 OK", headerParts[0])
        self.assertTrue(newHeader in headerParts)
        self.assertTrue(utils.ContentTypeHeader + utils.ContentTypeHtml in headerParts)
コード例 #7
0
 def logout(self, session, Headers, **ignored):
     session.pop(USER, None)
     redirectUrl = self._home
     response = redirectHttp % redirectUrl
     if not self._rememberMeCookie:
         yield response
         return
     cookieName = self.call.cookieName()
     for cookie in findCookies(Headers=Headers, name=cookieName):
         self.call.removeCookie(cookie)
     yield insertHeader(
         [response],
         'Set-Cookie: {}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/'.
         format(cookieName))
コード例 #8
0
    def testInsertHeader(self):
        def handleRequest(*args, **kwargs):
            yield utils.okHtml
            yield '<ht'
            yield 'ml/>'

        newHeader = 'Set-Cookie: session=dummySessionId1234; path=/'
        result = ''.join(utils.insertHeader(handleRequest(), newHeader))
        header, body = result.split(utils.CRLF * 2, 1)
        self.assertEquals('<html/>', body)
        headerParts = header.split(utils.CRLF)
        self.assertEquals("HTTP/1.0 200 OK", headerParts[0])
        self.assertTrue(newHeader in headerParts)
        self.assertTrue(utils.ContentTypeHeader +
                        utils.ContentTypeHtml in headerParts)
コード例 #9
0
    def handleRequest(self, session, Headers, **kwargs):
        extraHeader = None
        if 'user' not in session:
            cookieName = self.call.cookieName()
            for cookie in findCookies(Headers=Headers, name=cookieName):
                cookieDict = self.call.validateCookie(cookie)
                if cookieDict is not None:
                    session['user'] = cookieDict['value']
                    extraHeader = cookieDict['header']
                    break

        yield insertHeader(
            compose(self.all.handleRequest(session=session, Headers=Headers, **kwargs)),
            extraHeader
        )
コード例 #10
0
    def handleRequest(self, session, Headers, **kwargs):
        extraHeader = None
        if 'user' not in session:
            cookieName = self.call.cookieName()
            for cookie in findCookies(Headers=Headers, name=cookieName):
                cookieDict = self.call.validateCookie(cookie)
                if cookieDict is not None:
                    session['user'] = cookieDict['value']
                    extraHeader = cookieDict['header']
                    break

        yield insertHeader(
            compose(
                self.all.handleRequest(session=session,
                                       Headers=Headers,
                                       **kwargs)), extraHeader)
コード例 #11
0
 def handleRequest(self, arguments, Headers, **kwargs):
     debugId = self._getDebugId(Headers)
     debug = arguments.pop('debug', [None])[0] is not None or debugId
     if not debug:
         try:
             self._check(message='handleRequest')
             yield self.all.handleRequest(arguments=arguments, Headers=Headers, **kwargs)
         except EnvironmentError:
             yield 'HTTP/1.0 503 Service Temporarily Unavailable\r\n\r\n'
     else:
         debugId = self._registerDebugId(debugId=debugId, **kwargs)
         yield insertHeader(
                 compose(self.all.handleRequest(arguments=arguments, Headers=Headers, **kwargs)),
                 extraHeader='Set-Cookie: '+'; '.join([
                         self._cookiekey+debugId,
                         'Expires={0}'.format(self._zulutime().add(seconds=2*self._debugTimeout).rfc1123()),
                     ])
             )