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)))
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)
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=/'))
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))
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)
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))
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)
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 )
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)
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()), ]) )