Skip to content

Commit

Permalink
Use directly Link header value
Browse files Browse the repository at this point in the history
  • Loading branch information
JorgeMucientes committed Sep 30, 2024
1 parent 6b80a18 commit 788b569
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 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,18 +13,18 @@ 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 -> Header(LINK_HEADER_NAME, value.trimStart()) }
.map { value -> value.trimStart() }
}
?.ifEmpty { null }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class SiteWPAPIRestClient @Inject constructor(
private fun discoverApiEndpoint(
url: String
): String {
return discoveryWPAPIRestClient.discoverWPAPIBaseURL(url) // discover rest api endpoint
return discoveryWPAPIRestClient.discoverWPAPIBaseURL("https://grinderstore.in") // discover rest api endpoint
?: WPAPIDiscoveryUtils.buildDefaultRESTBaseUrl(url)
}
}

0 comments on commit 788b569

Please sign in to comment.