Ticket #5911: support_httponly_flag.2.diff

File support_httponly_flag.2.diff, 2.6 KB (added by Reed Loden, 7 years ago)

Same as above but includes a test

  • twisted/web/http.py

     
    952952            else:
    953953                self.transport.write(data)
    954954
    955     def addCookie(self, k, v, expires=None, domain=None, path=None, max_age=None, comment=None, secure=None):
     955    def addCookie(self, k, v, expires=None, domain=None, path=None, max_age=None, comment=None, secure=None, httponly=None):
    956956        """
    957957        Set an outgoing HTTP cookie.
    958958
     
    973973            cookie = cookie +"; Comment=%s" % comment
    974974        if secure:
    975975            cookie = cookie +"; Secure"
     976        if httponly:
     977            cookie = cookie +"; HttpOnly"
    976978        self.cookies.append(cookie)
    977979
    978980    def setResponseCode(self, code, message=None):
  • twisted/web/iweb.py

     
    218218        """
    219219
    220220
    221     def addCookie(k, v, expires=None, domain=None, path=None, max_age=None, comment=None, secure=None):
     221    def addCookie(k, v, expires=None, domain=None, path=None, max_age=None, comment=None, secure=None, httponly=None):
    222222        """
    223223        Set an outgoing HTTP cookie.
    224224
  • twisted/web/test/test_webclient.py

     
    23292329            cookieJar,
    23302330            'http://example.com:1234/foo?bar',
    23312331            ['foo=1; cow=moo; Path=/foo; Comment=hello',
    2332              'bar=2; Comment=goodbye'])
     2332             'bar=2; Comment=goodbye',
     2333             'baz=3; HttpOnly'])
    23332334        return cookieJar, reqres
    23342335
    23352336
     
    23572358        self.assertEqual(cookie.comment, 'goodbye')
    23582359        self.assertIdentical(cookie.get_nonstandard_attr('cow'), None)
    23592360
     2361        cookie = cookies['baz']
     2362        self.assertEqual(cookie.version, 0)
     2363        self.assertEqual(cookie.name, 'baz')
     2364        self.assertEqual(cookie.value, '3')
     2365        self.assertEqual(cookie.secure, False)
     2366        self.assertEqual(cookie.has_nonstandard_attr('HttpOnly'), True)
    23602367
     2368
    23612369    def test_sendCookie(self):
    23622370        """
    23632371        L{cookielib.CookieJar.add_cookie_header} adds a cookie header to a fake
     
    23722380        jar.add_cookie_header(request)
    23732381        self.assertEqual(
    23742382            request.get_header('Cookie', None),
    2375             'foo=1; bar=2')
     2383            'foo=1; bar=2; baz=3')
    23762384
    23772385
    23782386