Skip to content

Commit

Permalink
fix: http handler set cookie only when cookie_enabled=true. (#16992)
Browse files Browse the repository at this point in the history
  • Loading branch information
youngsofun authored Dec 4, 2024
1 parent 5581b05 commit e1cfad6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/query/service/src/servers/http/middleware/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,11 @@ impl<E> HTTPSessionEndpoint<E> {
}
}

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

let session = session_manager.register_session(session)?;

Expand Down
8 changes: 8 additions & 0 deletions tests/suites/1_stateful/09_http_handler/09_0009_cookie.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,17 @@ def test_temp_table():
assert not session_state["need_keep_alive"]


def test_no_cookie_if_not_enabled():
client = requests.session()
resp = do_query(client, "select 1")
assert resp.status_code == 200, resp.text
assert len(client.cookies.items()) == 0


def main():
test_simple()
test_temp_table()
test_no_cookie_if_not_enabled()


if __name__ == "__main__":
Expand Down

0 comments on commit e1cfad6

Please sign in to comment.