-
Notifications
You must be signed in to change notification settings - Fork 76
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
Conversation
ae6fec6
to
05c5139
Compare
@@ -426,3 +426,14 @@ open class R2AudiobookActivity : AppCompatActivity(), CoroutineScope, IR2Activit | |||
} | |||
|
|||
} | |||
|
|||
internal fun Link.withBaseUrl(baseUrl: String): Link { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
readium/shared/src/main/java/org/readium/r2/shared/fetcher/Resource.kt
Outdated
Show resolved
Hide resolved
@@ -110,43 +110,30 @@ data class HttpResponse( | |||
val mediaType: MediaType, | |||
) { | |||
|
|||
private val httpHeaders = HttpHeaders(headers) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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.
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
'sshouldInterceptRequest()
API is used to intercept and serve the resources under the custom originhttps://readium
.https://readium/publication/
. It supports byte range requests for media resources.assets/
directory are served under the base URLhttps://readium/assets/
usingWebViewAssetLoader
.EpubNavigatorFragment.Configuration.servedAssets
. All assets under thereadium/
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 thebaseUrl
argument, which is now optional.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.