Skip to content

Commit

Permalink
Fix Request's key missing headers
Browse files Browse the repository at this point in the history
  • Loading branch information
gamepro65 committed Sep 5, 2023
1 parent 3f34a6b commit c0dfa23
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
8 changes: 8 additions & 0 deletions picasso/src/main/java/com/squareup/picasso3/Request.kt
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ class Request internal constructor(builder: Builder) {
val path = data.uri.toString()
builder.ensureCapacity(path.length + KEY_PADDING)
builder.append(path)

data.headers?.toMultimap()?.let {
builder
.append(KEY_SEPARATOR)
.append("headers:")
.append(it)
}
} else {
builder.ensureCapacity(KEY_PADDING)
builder.append(data.resourceId)
Expand Down Expand Up @@ -330,6 +337,7 @@ class Request internal constructor(builder: Builder) {
priority = request.priority
memoryPolicy = request.memoryPolicy
networkPolicy = request.networkPolicy
headers = request.headers
}

fun hasImage(): Boolean {
Expand Down
25 changes: 25 additions & 0 deletions picasso/src/test/java/com/squareup/picasso3/RequestCreatorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -710,4 +710,29 @@ class RequestCreatorTest {
assertThat(actionCaptor.value.request.headers!![CUSTOM_HEADER_NAME])
.isEqualTo(CUSTOM_HEADER_VALUE)
}

@Test fun customHeadersArePartOfRequestKey() {
RequestCreator(picasso, URI_1, 0)
.addHeader(CUSTOM_HEADER_NAME, CUSTOM_HEADER_VALUE)
.into(mockImageViewTarget())
verify(picasso).enqueueAndSubmit(actionCaptor.capture())
assertThat(actionCaptor.value.request.key).isEqualTo(
"""
http://example.com/1.png
headers:{cache-control=[no-cache]}
""".trimIndent()
)
}

@Test fun imageViewActionWithCustomHeadersCopiesHeaders() {
RequestCreator(picasso, URI_1, 0)
.addHeader(CUSTOM_HEADER_NAME, CUSTOM_HEADER_VALUE)
.into(mockImageViewTarget())
verify(picasso).enqueueAndSubmit(actionCaptor.capture())

val newRequest = actionCaptor.value.request.newBuilder().build()

assertThat(newRequest.headers!![CUSTOM_HEADER_NAME]).isEqualTo(CUSTOM_HEADER_VALUE)
}
}

0 comments on commit c0dfa23

Please sign in to comment.