Skip to content

Commit

Permalink
refactor: set path of cookie.
Browse files Browse the repository at this point in the history
  • Loading branch information
youngsofun committed Dec 6, 2024
1 parent 5ca9e64 commit 6a17c5f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/query/service/src/servers/http/middleware/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ pub struct HTTPSessionEndpoint<E> {
pub auth_manager: Arc<AuthMgr>,
}

fn make_cookie(name: impl Into<String>, value: impl Into<String>) -> Cookie {
let mut cookie = Cookie::new_with_str(name, value);
cookie.set_path("/");
cookie
}

impl<E> HTTPSessionEndpoint<E> {
#[async_backtrace::framed]
async fn auth(&self, req: &Request, query_id: String) -> Result<HttpQueryContext> {
Expand Down Expand Up @@ -364,17 +370,15 @@ impl<E> HTTPSessionEndpoint<E> {
Some(id1.clone())
}
(Some(id), None) => {
req.cookie()
.add(Cookie::new_with_str(COOKIE_SESSION_ID, id));
req.cookie().add(make_cookie(COOKIE_SESSION_ID, id));
Some(id.clone())
}
(None, Some(id)) => Some(id.clone()),
(None, None) => {
if cookie_enabled {
let id = Uuid::new_v4().to_string();
info!("new session id: {}", id);
req.cookie()
.add(Cookie::new_with_str(COOKIE_SESSION_ID, &id));
req.cookie().add(make_cookie(COOKIE_SESSION_ID, &id));
Some(id)
} else {
None
Expand All @@ -399,8 +403,7 @@ impl<E> HTTPSessionEndpoint<E> {

if cookie_enabled {
let ts = unix_ts().as_secs().to_string();
req.cookie()
.add(Cookie::new_with_str(COOKIE_LAST_ACCESS_TIME, ts));
req.cookie().add(make_cookie(COOKIE_LAST_ACCESS_TIME, ts));
}

let session = session_manager.register_session(session)?;
Expand Down

0 comments on commit 6a17c5f

Please sign in to comment.