Skip to content

Commit

Permalink
Merge pull request #207 from hotwired/ignore-esm-blob-urls
Browse files Browse the repository at this point in the history
Ignore blob:http* ESM shim requests when cold booting the WebView
  • Loading branch information
jayohms authored Dec 8, 2021
2 parents 6522c8b + 67fdbfe commit 8061c9d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dev.hotwire.turbo.http
import android.webkit.WebResourceRequest
import android.webkit.WebResourceResponse
import dev.hotwire.turbo.session.TurboSession
import dev.hotwire.turbo.util.isHttpGetRequest
import dev.hotwire.turbo.util.logEvent

internal class TurboWebViewRequestInterceptor(val session: TurboSession) {
Expand Down Expand Up @@ -38,8 +39,7 @@ internal class TurboWebViewRequestInterceptor(val session: TurboSession) {
}

private fun shouldInterceptRequest(request: WebResourceRequest): Boolean {
return request.method.equals("GET", ignoreCase = true) &&
request.url.scheme?.startsWith("HTTP", ignoreCase = true) == true
return request.isHttpGetRequest()
}

private fun logCurrentVisitResult(url: String, result: TurboHttpRepository.Result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,8 @@ class TurboSession internal constructor(
*/
override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {
val location = request.url.toString()
val isColdBootRedirect = isColdBooting && currentVisit?.location != location
val isHttpRequest = request.isHttpGetRequest()
val isColdBootRedirect = isHttpRequest && isColdBooting && currentVisit?.location != location
val shouldOverride = isReady || isColdBootRedirect

// Don't allow onPageFinished to process its
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.animation.ArgbEvaluator
import android.animation.ValueAnimator
import android.content.Context
import android.os.Handler
import android.webkit.WebResourceRequest
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.google.gson.reflect.TypeToken
Expand Down Expand Up @@ -37,6 +38,11 @@ internal fun File.deleteAllFilesInDirectory() {
}
}

internal fun WebResourceRequest.isHttpGetRequest(): Boolean {
return method.equals("GET", ignoreCase = true) &&
url.scheme?.startsWith("HTTP", ignoreCase = true) == true
}

internal fun Any.toJson(): String {
return gson.toJson(this)
}
Expand Down

0 comments on commit 8061c9d

Please sign in to comment.