[libsoup/tingping/same-site-api-change] Simplify soup_cookie_jar_get_cookie_list_with_same_site_info() API
- From: Patrick Griffis <pgriffis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup/tingping/same-site-api-change] Simplify soup_cookie_jar_get_cookie_list_with_same_site_info() API
- Date: Tue, 28 Jan 2020 11:33:04 +0000 (UTC)
commit 181567224fd5f1fbc74ab10fe6d8029467f30daa
Author: Patrick Griffis <pgriffis igalia com>
Date: Tue Jan 28 03:29:27 2020 -0800
Simplify soup_cookie_jar_get_cookie_list_with_same_site_info() API
This changes passing an HTTP method string to just passing a boolean
for if it is a safe method or not. This slightly simplifies usage
within WebKit.
libsoup/soup-cookie-jar.c | 26 ++++++++++++--------------
libsoup/soup-cookie-jar.h | 2 +-
tests/samesite-test.c | 2 +-
3 files changed, 14 insertions(+), 16 deletions(-)
---
diff --git a/libsoup/soup-cookie-jar.c b/libsoup/soup-cookie-jar.c
index d7b2d7dc..7dea8f77 100644
--- a/libsoup/soup-cookie-jar.c
+++ b/libsoup/soup-cookie-jar.c
@@ -302,7 +302,7 @@ compare_cookies (gconstpointer a, gconstpointer b, gpointer jar)
static gboolean
cookie_is_valid_for_same_site_policy (SoupCookie *cookie,
- const char *method,
+ gboolean is_safe_method,
SoupURI *uri,
SoupURI *top_level,
SoupURI *cookie_uri,
@@ -318,7 +318,7 @@ cookie_is_valid_for_same_site_policy (SoupCookie *cookie,
return TRUE;
if (policy == SOUP_SAME_SITE_POLICY_LAX && is_top_level_navigation &&
- (SOUP_METHOD_IS_SAFE (method) || for_http == FALSE))
+ (is_safe_method || for_http == FALSE))
return TRUE;
if (is_top_level_navigation && cookie_uri == NULL)
@@ -332,7 +332,7 @@ get_cookies (SoupCookieJar *jar,
SoupURI *uri,
SoupURI *top_level,
SoupURI *site_for_cookies,
- const char *method,
+ gboolean is_safe_method,
gboolean for_http,
gboolean is_top_level_navigation,
gboolean copy_cookies)
@@ -369,7 +369,7 @@ get_cookies (SoupCookieJar *jar,
g_strdup (cur),
new_head);
} else if (soup_cookie_applies_to_uri (cookie, uri) &&
- cookie_is_valid_for_same_site_policy (cookie, method, uri, top_level,
+ cookie_is_valid_for_same_site_policy (cookie, is_safe_method, uri,
top_level,
site_for_cookies,
is_top_level_navigation,
for_http) &&
(for_http || !cookie->http_only))
@@ -426,7 +426,7 @@ soup_cookie_jar_get_cookies (SoupCookieJar *jar, SoupURI *uri,
g_return_val_if_fail (SOUP_IS_COOKIE_JAR (jar), NULL);
g_return_val_if_fail (uri != NULL, NULL);
- cookies = get_cookies (jar, uri, NULL, NULL, NULL, for_http, FALSE, FALSE);
+ cookies = get_cookies (jar, uri, NULL, NULL, TRUE, for_http, FALSE, FALSE);
if (cookies) {
char *result = soup_cookies_to_cookie_header (cookies);
@@ -470,7 +470,7 @@ soup_cookie_jar_get_cookie_list (SoupCookieJar *jar, SoupURI *uri, gboolean for_
g_return_val_if_fail (SOUP_IS_COOKIE_JAR (jar), NULL);
g_return_val_if_fail (uri != NULL, NULL);
- return get_cookies (jar, uri, NULL, NULL, NULL, for_http, FALSE, TRUE);
+ return get_cookies (jar, uri, NULL, NULL, TRUE, for_http, FALSE, TRUE);
}
/**
@@ -479,8 +479,7 @@ soup_cookie_jar_get_cookie_list (SoupCookieJar *jar, SoupURI *uri, gboolean for_
* @uri: a #SoupURI
* @top_level: (nullable): a #SoupURI for the top level document
* @site_for_cookies: (nullable): a #SoupURI indicating the origin to get cookies for
- * @method: (nullable): the HTTP method requesting the cookies, this
- * should only be %NULL when @for_http is %FALSE
+ * @is_safe_method:: if the HTTP method is safe, ignored when @for_http is %FALSE
* @for_http: whether or not the return value is being passed directly
* to an HTTP operation
* @is_top_level_navigation: whether or not the HTTP request is part of
@@ -501,15 +500,14 @@ soup_cookie_jar_get_cookie_list_with_same_site_info (SoupCookieJar *jar,
SoupURI *uri,
SoupURI *top_level,
SoupURI *site_for_cookies,
- const char *method,
- gboolean for_http,
- gboolean is_top_level_navigation)
+ gboolean is_safe_method,
+ gboolean for_http,
+ gboolean is_top_level_navigation)
{
g_return_val_if_fail (SOUP_IS_COOKIE_JAR (jar), NULL);
g_return_val_if_fail (uri != NULL, NULL);
- g_return_val_if_fail (method != NULL || for_http == FALSE, NULL);
- return get_cookies (jar, uri, top_level, site_for_cookies, g_intern_string (method), for_http,
is_top_level_navigation, TRUE);
+ return get_cookies (jar, uri, top_level, site_for_cookies, is_safe_method, for_http,
is_top_level_navigation, TRUE);
}
static const char *
@@ -806,7 +804,7 @@ msg_starting_cb (SoupMessage *msg, gpointer feature)
cookies = soup_cookie_jar_get_cookie_list_with_same_site_info (jar, soup_message_get_uri (msg),
soup_message_get_first_party (msg),
soup_message_get_site_for_cookies
(msg),
- msg->method,
+ SOUP_METHOD_IS_SAFE (msg->method),
TRUE,
soup_message_get_is_top_level_navigation (msg));
if (cookies != NULL) {
char *cookie_header = soup_cookies_to_cookie_header (cookies);
diff --git a/libsoup/soup-cookie-jar.h b/libsoup/soup-cookie-jar.h
index 639df342..7b6c0f90 100644
--- a/libsoup/soup-cookie-jar.h
+++ b/libsoup/soup-cookie-jar.h
@@ -65,7 +65,7 @@ GSList * soup_cookie_jar_get_cookie_list_with_same_site_info (
SoupURI *uri,
SoupURI *top_level,
SoupURI
*site_for_cookies,
- const char *method,
+ gboolean
is_safe_method,
gboolean for_http,
gboolean
is_top_level_navigation);
SOUP_AVAILABLE_IN_2_24
diff --git a/tests/samesite-test.c b/tests/samesite-test.c
index 675f1e57..4c5873f8 100644
--- a/tests/samesite-test.c
+++ b/tests/samesite-test.c
@@ -82,7 +82,7 @@ same_site_test (SameSiteFixture *fixture, gconstpointer user_data)
fixture->cookies = soup_cookie_jar_get_cookie_list_with_same_site_info (fixture->jar,
fixture->origin_uri,
test->cross_origin ?
fixture->cross_uri : fixture->origin_uri,
test->cookie_uri_is_origin ?
fixture->origin_uri : NULL,
- test->unsafe_method ? "POST"
: "GET",
+ !test->unsafe_method,
test->javascript ? FALSE :
TRUE,
test->top_level_nav);
assert_highest_policy_visible (fixture->cookies, test->visible_policy);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]