Is there a clean and spec-conformant way to define a custom URL scheme that acts as an adapter on the resource returned by another URL?
I have already defined a custom URL protocol which returns a decrypted representation of a local file. So, for instance, in my code,
decrypted-file:///path/to/file
transparently decrypts the file you would get from file:///path/to/file
. However, this only works for local files. No fun! I am hoping that the URL specification allows a clean way that I could generalize this by defining a new URL scheme as a kind of adapter on existing URLs.
For example, could I instead define a custom URL scheme decrypted:
that could be used as an adapter that prefixes another absolute URL that retrieved a resource? Then I could just do
decrypted:file:///path/to/file
or decrypted:http://server/path/to/file
or decrypted:ftp://server/path/to/file
or whatever. This would make my decrypted:
protocol composable with all existing URL schemes that do file retrieval.
Java does something similar with the jar:
URL scheme but from my reading of RFC 3986 it seems like this Java technology violates the URL spec. The embedded URL is not properly byte-encoded, so any /
, ?
, or #
delimiters in the embedded URL should officially be treated as segment delimiters in the embedding URL (even if that's not what JarURLConnection does). I want to stay within the specs.
Is there a nice and correct way to do this? Or is the only option to byte-encode the entire embedded URL (i.e., decrypted:file%3A%2F%2F%2Fpath%2Fto%2Ffile
, which is not so nice)?
Is what I'm suggesting (URL adapters) done anywhere else? Or is there a deeper reason why this is misguided?
myscheme:<originalurl>
is a syntactically valid URL, and-resourceSpecifier
lets you grab the<originalurl>
, and this is enough for a simple URL adapter protocol. Hurray! However,<originalurl>
does not match any well-defined semantic component of the outer URL but instead matches its hierarchical-part plus query component plus fragment components. So simple prefixing like this would not work if, for instance, I also wanted to add a query component to the outer URL, since the inner URL's query component would count as belonging to the outer URL. Phew. – Diageotropism