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

2/3 Remove the need for an HTTP server #259

Merged
merged 39 commits into from
Sep 7, 2022

Conversation

mickael-menu
Copy link
Member

@mickael-menu mickael-menu commented Aug 5, 2022

Review notes

The Settings API PRs are numbered in the order of merge, but should be reviewed in reverse order, starting with #141.

This PR refactor the EPUB navigator to support serving the resources without an HTTP server. This was necessary to inject the new user settings API.

How resources are served?

The WebViewClient's shouldInterceptRequest() API is used to intercept and serve the resources under the custom origin https://readium.

  • Publication resources are served manually under the base URL https://readium/publication/. It supports byte range requests for media resources.
  • Files in the app's assets/ directory are served under the base URL https://readium/assets/ using WebViewAssetLoader.
    • The custom assets must be explicitly allowed to be served, using EpubNavigatorFragment.Configuration.servedAssets. All assets under the readium/ folder are automatically allowed.

How to opt-in?

The EpubNavigatorFragment is using this new method of serving the EPUB resources by default, unless you provide the baseUrl argument, which is now optional.

⚠️ Using this new method is incompatible with the legacy EPUB settings API.

Error page

The PR introduces a (overridable in the test app) error page for when a resource fails to be loaded. Previously the navigator was broken and you were stuck in the default web view 404 page.

404


@mickael-menu mickael-menu changed the title Remove the need for an HTTP server 2/3 Remove the need for an HTTP server Aug 9, 2022
@@ -426,3 +426,14 @@ open class R2AudiobookActivity : AppCompatActivity(), CoroutineScope, IR2Activit
}

}

internal fun Link.withBaseUrl(baseUrl: String): Link {
Copy link
Member Author

Choose a reason for hiding this comment

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

This used to be shared with the EPUB navigator, I moved it there as R2AudiobookActivity will soon be deprecated.

return null
}

private fun injectScriptFile(view: WebView?, scriptFile: String) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This function was not used.

@@ -110,43 +110,30 @@ data class HttpResponse(
val mediaType: MediaType,
) {

private val httpHeaders = HttpHeaders(headers)
Copy link
Member Author

Choose a reason for hiding this comment

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

I extracted the code into its own HttpHeaders helper class to be reusable in the EPUB navigator when parsing the Range request headers.

internal class EpubDeobfuscator(private val pubId: String) {

fun transform(resource: Resource): Resource = DeobfuscatingResource(resource)
Copy link
Member Author

Choose a reason for hiding this comment

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

There was a performance issue here, as using a TransformingResource for non obfuscated resources meant that media files were loaded entirely to compute the "transformed" length.


<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Resource not found</title>
Copy link
Member Author

Choose a reason for hiding this comment

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

It's exactly the same as the 404.xhtml in the navigator module. I copied it as an example on how to override it in the test app.

@mickael-menu mickael-menu requested a review from qnga August 16, 2022 15:34
@mickael-menu mickael-menu marked this pull request as ready for review August 16, 2022 15:34
@mickael-menu mickael-menu merged commit f0b36f8 into feature/settings Sep 7, 2022
@mickael-menu mickael-menu deleted the feature/settings+server branch September 7, 2022 13:32
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.

3 participants