Closed alkoclick closed 4 years ago
Hmm, definitely looks like a problem - could you clarify how you're trying to use it? Is it possible to use val url
directly without using the Galimatias parser? If I recall correctly, your issue before was that it was stripping the query and fragment from the path
, but you can now do something like:
url.value = "/path?query#fragment"
fun WebBrowser.getQueryParams(): Parameters =
parseQueryString(
URL.parse(httpRequestInfo.requestedUrl).query()?.replace("+", " ")
?: ""
)
(parseQueryString is from ktor)
Instead of that, I would love to instead do:
fun WebBrowser.getQueryParams(): Parameters =
parseQueryString(
url(simpleUrlParser).query.value
?: ""
)
Generally there is a bunch of extension methods such as val KVar<URL>.query
that I would like to use, but they are currently unusable :/
This should be an easy fix, just trying to think through the ergonomics. How about something like this:
class WebBrowser {
...
val gurl : KVar<URL> = url.map(object : ReversibleFunction<String, URL>(label = "gurl") {
override fun invoke(from: String): URL {
return URL.parse(this@WebBrowser.httpRequestInfo.requestedUrl).resolve(from)
}
override fun reverse(original: String, change: URL): String {
return change.pathQueryFragment
}
} )
...
}
This would allow you to use the KVar<URL>
extension methods on gurl
:
gurl.query.value = "query"
Yeah, but I was trying to have the functionality of WebBrowser.url
as well. This is currently pushState
and I dunno if you're doing anything else with it? So this is about operating on WebBrowser.url using the methods created for Kvar (query, path, fragment, etc)
I'm afraid I'm not sure what you mean, could you give an example of how it should work?
No, sorry, my bad. I had missed that in your example, gurl is mapped on url (url.map
). That is an easy fix indeed and has the functionality I expected, though I would also add some short documentation about this (previously some examples did url(simpleUrlParser)
so maybe others like me are using this, and it's currently broken OOTB)
Gotcha, I'll search the documentation for references to simpleUrlParser
and update them.
Again, I may be misdirected here somehow, but seeing the new
WebBrowser.url
I wanted to try it out in the following way (which used to work)url(simpleUrlParser)
The way I understand this, this should also allow me to access the the extensions such as query, path, etc. However, this throws immediately as the scheme is missing
Adding the above line to the FeatureApp, produces the following:
In WebBrowser.url we are in fact dropping the scheme:
The options I see are:
URL.parse("http://kweb.io" + from)
going (because we don't have the info at the source, i.e WebBrowser.url). Can easily work, but if the user tries to access e.g the host, they're in for a surprise. Pretty nasty hackURL.parse(httpRequestInfo.requestedUrl)
... which is basically what WebBrowser.url does and then it throws the result away. Smells pretty bad for concurrency as well. Eh.val WebBrowser.fullUrl : KVar<String>
and make the current WebBrowser.url a dependent KVar on it (I think you had a design for that somewhere). Looks pretty good tbh, plus not sure why we're missing that full url anyway?