Skip to content

Commit

Permalink
Migrate to http.cookies.
Browse files Browse the repository at this point in the history
  • Loading branch information
kiarn committed May 8, 2023
1 parent 52b39c4 commit c5dab99
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
7 changes: 2 additions & 5 deletions ajenti-core/aj/gate/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import time
import gevent
from socketio import Namespace
from cookies import Cookies
from http.cookies import SimpleCookie
from gevent.timeout import Timeout
from jadi import service

Expand Down Expand Up @@ -129,10 +129,7 @@ def obtain_session(self, env):
cookie_str = env.get('HTTP_COOKIE', None)
session = None
if cookie_str:
cookie = Cookies.from_request(
cookie_str,
ignore_bad_cookies=True,
).get('session', None)
cookie = SimpleCookie(cookie_str).get('session', None)
if cookie and cookie.value:
if cookie.value in self.sessions:
# Session found
Expand Down
15 changes: 7 additions & 8 deletions ajenti-core/aj/gate/session.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import time
import logging
from cookies import Cookie
from http.cookies import SimpleCookie

from aj.gate.gate import WorkerGate

Expand Down Expand Up @@ -64,13 +64,12 @@ def set_cookie(self, http_context):
Adds headers to :class:`aj.http.HttpContext` that set
the session cookie
"""
cookie = Cookie(
'session',
self.key,
path='/',
httponly=True
).render_response()
http_context.add_header('Set-Cookie', cookie)

cookie = SimpleCookie()
cookie['session'] = self.key
cookie['session']['path'] = '/'
cookie['session']['httponly'] = True
http_context.add_header('Set-Cookie', cookie.output(header=''))

def serialize(self):
return {
Expand Down

0 comments on commit c5dab99

Please sign in to comment.