Ticket #8077: 8077.diff

File 8077.diff, 2.5 KB (added by Pawel, 3 years ago)
  • twisted/web/server.py

    diff --git a/twisted/web/server.py b/twisted/web/server.py
    index 2ec4d58..c19ae90 100644
    a b class Request(Copyable, http.Request, components.Componentized): 
    392392    def getSession(self, sessionInterface=None):
    393393        # Session management
    394394        if not self.session:
    395             cookiename = b"_".join([b'TWISTED_SESSION'] + self.sitepath)
     395            cookiename = "_".join(['TWISTED_SESSION'] + self.sitepath)
    396396            sessionCookie = self.getCookie(cookiename)
    397397            if sessionCookie:
    398398                try:
    class Request(Copyable, http.Request, components.Componentized): 
    402402            # if it still hasn't been set, fix it up.
    403403            if not self.session:
    404404                self.session = self.site.makeSession()
    405                 self.addCookie(cookiename, self.session.uid, path=b'/')
     405                self.addCookie(cookiename, self.session.uid, path='/')
    406406        self.session.touch()
    407407        if sessionInterface:
    408408            return self.session.getComponent(sessionInterface)
  • twisted/web/test/test_web.py

    diff --git a/twisted/web/test/test_web.py b/twisted/web/test/test_web.py
    index ae5a946..60222b9 100644
    a b class SessionTests(unittest.TestCase): 
    209209
    210210
    211211
     212
    212213# Conditional requests:
    213214# If-None-Match, If-Modified-Since
    214215
    class RequestTests(unittest.TestCase): 
    551552        # failure
    552553        self.assertEqual(1, len(self.flushLoggedErrors()))
    553554
     555    def test_setDefaultSessionCookie(self):
     556        """
     557        """
     558        d = DummyChannel()
     559        request = server.Request(d, 1)
     560        request.site = server.Site(resource.Resource())
     561        request.sitepath = []
     562        request.gotLength(0)
     563        session = request.getSession()
     564        request.requestReceived(b'GET', b'/', b'HTTP/1.0')
     565        cookie_name, _ = request.cookies[0].split("=", 1)
     566        # avoid delayed calls lingering after test exit
     567        session.expire()
     568        self.assertTrue(bool(request.session))
     569        self.assertEqual(cookie_name, "TWISTED_SESSION")
    554570
    555571
    556572class GzipEncoderTests(unittest.TestCase):
  • new file twisted/web/topfiles/8077.bugfix

    diff --git a/twisted/web/topfiles/8077.bugfix b/twisted/web/topfiles/8077.bugfix
    new file mode 100644
    index 0000000..6ba6393
    - +  
     1twisted.web.server.Request.getSession() correctly sets default session cookie in Python3, previously cookie name
     2was set to b"TWISTED_SESSION" instead of just "TWISTED_SESSION"