mirror of
https://github.com/kiwix/libkiwix.git
synced 2025-06-26 10:11:30 +00:00
Server sets userlang cookie as global and permanent
Without specifying the "Path" attribute of the cookie in the "Set-Cookie" header we end up with multiple instances of the cookie for different URLs. We want a single "global" cookie for kiwix-serve. Besides we want it to be "permanent" rather than a session cookie, hence the large (1-year-long) TTL value for the "Max-Age" attribute.
This commit is contained in:
committed by
Matthieu Gautier
parent
fcb97c3c06
commit
e35e7585e0
@ -68,12 +68,13 @@ fullURL2LocalURL(const std::string& full_url, const std::string& rootLocation)
|
||||
} // unnamed namespace
|
||||
|
||||
RequestContext::RequestContext(struct MHD_Connection* connection,
|
||||
std::string rootLocation,
|
||||
std::string _rootLocation,
|
||||
const std::string& _url,
|
||||
const std::string& _method,
|
||||
const std::string& version) :
|
||||
rootLocation(_rootLocation),
|
||||
full_url(_url),
|
||||
url(fullURL2LocalURL(_url, rootLocation)),
|
||||
url(fullURL2LocalURL(_url, _rootLocation)),
|
||||
method(str2RequestMethod(_method)),
|
||||
version(version),
|
||||
requestIndex(s_requestIndex++),
|
||||
@ -193,6 +194,10 @@ std::string RequestContext::get_full_url() const {
|
||||
return full_url;
|
||||
}
|
||||
|
||||
std::string RequestContext::get_root_path() const {
|
||||
return rootLocation.empty() ? "/" : rootLocation;
|
||||
}
|
||||
|
||||
bool RequestContext::is_valid_url() const {
|
||||
return !url.empty();
|
||||
}
|
||||
|
@ -91,6 +91,7 @@ class RequestContext {
|
||||
std::string get_url() const;
|
||||
std::string get_url_part(int part) const;
|
||||
std::string get_full_url() const;
|
||||
std::string get_root_path() const;
|
||||
|
||||
std::string get_query() const { return queryString; }
|
||||
|
||||
@ -136,6 +137,7 @@ class RequestContext {
|
||||
};
|
||||
|
||||
private: // data
|
||||
std::string rootLocation;
|
||||
std::string full_url;
|
||||
std::string url;
|
||||
RequestMethod method;
|
||||
|
@ -388,7 +388,9 @@ MHD_Result Response::send(const RequestContext& request, MHD_Connection* connect
|
||||
}
|
||||
|
||||
if ( ! request.user_language_comes_from_cookie() ) {
|
||||
const std::string cookie = "userlang=" + request.get_user_language();
|
||||
const std::string cookie = "userlang=" + request.get_user_language()
|
||||
+ ";Path=" + request.get_root_path()
|
||||
+ ";Max-Age=31536000";
|
||||
MHD_add_response_header(response, MHD_HTTP_HEADER_SET_COOKIE, cookie.c_str());
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user