Skip to content

Commit

Permalink
Merge pull request #3104 from wordpress-mobile/fix/12715-fix-url-disc…
Browse files Browse the repository at this point in the history
…overability-crash

Split Link header values into different items
  • Loading branch information
JorgeMucientes authored Sep 30, 2024
2 parents 7e2a6b2 + 79ea8e5 commit 06e2a17
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.wordpress.android.fluxc.network.discovery

import com.android.volley.Header
import com.android.volley.NetworkResponse
import com.android.volley.ParseError
import com.android.volley.Response
Expand All @@ -14,15 +13,19 @@ class WPAPIHeadRequest(
url: String,
errorListener: BaseErrorListener,
private val mListener: Listener<String?>
) : BaseRequest<List<Header>?>(Method.HEAD, url, errorListener) {
override fun deliverResponse(response: List<Header>?) {
val endpoint = response?.firstNotNullOfOrNull { extractEndpointFromLinkHeader(it.value) }
) : BaseRequest<List<String>?>(Method.HEAD, url, errorListener) {
override fun deliverResponse(response: List<String>?) {
val endpoint = response?.firstNotNullOfOrNull { extractEndpointFromLinkHeader(it) }
mListener.onResponse(endpoint)
}

override fun parseNetworkResponse(response: NetworkResponse): Response<List<Header>?>? {
override fun parseNetworkResponse(response: NetworkResponse): Response<List<String>?>? {
val headers = response.allHeaders
?.filter { it.name.equals(LINK_HEADER_NAME, ignoreCase = true) }
?.flatMap {
it.value.split(",")
.map { value -> value.trimStart() }
}
?.ifEmpty { null }

return if (headers != null) {
Expand Down

0 comments on commit 06e2a17

Please sign in to comment.