Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache URL Override #8234

Merged
merged 13 commits into from
Mar 22, 2024
Merged

Cache URL Override #8234

merged 13 commits into from
Mar 22, 2024

Conversation

yschimke
Copy link
Collaborator

@yschimke yschimke commented Feb 3, 2024

A minimal change to allow a cacheUrlOverride on request for the following examples

  • Define the canonical resource this request represents, such as the origin server for a CDN request
  • Remove transient query params such as S3 tokens
  • A narrow window of POST support - by declaring a POST should otherwise be treated as a GET, and define an appropriate unique url to represent the body if relevant.

It is implemented almost entirely within CacheInterceptor, mutating the request/response that Cache sees to avoid a broader change such as supporting POSTs.

Addresses #8211 also #8113

@yschimke yschimke changed the title [For discussion] Cache URL Override Cache URL Override Feb 3, 2024
@yschimke yschimke marked this pull request as ready for review February 3, 2024 11:57
Copy link
Member

@swankjesse swankjesse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great feature. Very small impact on the public API, very big impact on what people can do with OkHttp.

var recordedRequest = server.takeRequest()
assertThat(recordedRequest.method).isEqualTo("POST")
assertThat(recordedRequest.path)
.isEqualTo("/lookup?ct")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Off-topic: we’re naughty for having a field called path that contains a path and a query. Thanks for confirming that we use the right URL for these!

okhttp/src/main/kotlin/okhttp3/Request.kt Outdated Show resolved Hide resolved
okhttp/src/test/java/okhttp3/CacheTest.kt Outdated Show resolved Hide resolved
okhttp/src/test/java/okhttp3/CacheTest.kt Outdated Show resolved Hide resolved
okhttp/src/test/java/okhttp3/CacheTest.kt Outdated Show resolved Hide resolved
@@ -1048,6 +1049,7 @@ public class okhttp3/Request$Builder {
public fun addHeader (Ljava/lang/String;Ljava/lang/String;)Lokhttp3/Request$Builder;
public fun build ()Lokhttp3/Request;
public fun cacheControl (Lokhttp3/CacheControl;)Lokhttp3/Request$Builder;
public final fun cacheUrlOverride (Lokhttp3/HttpUrl;)Lokhttp3/Request$Builder;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that we’re not adding OkHttpExperimentalApi on this, and so we’re committing to this exact API and name. I’m okay with that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we reconsider as a policy for new API?

yschimke and others added 4 commits March 21, 2024 21:50
Co-authored-by: Jesse Wilson <jwilson@squareup.com>
Co-authored-by: Jesse Wilson <jwilson@squareup.com>
Co-authored-by: Jesse Wilson <jwilson@squareup.com>
Co-authored-by: Jesse Wilson <jwilson@squareup.com>
@yschimke yschimke merged commit 737efde into square:master Mar 22, 2024
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants