Skip to content

Commit

Permalink
fix: Fix #88 illegal access - "module java.base does not "opens java.…
Browse files Browse the repository at this point in the history
…net" to unnamed" (#245)

Fix 'Unable to make field private java.lang.String java.net.URL.host accessible: module java.base does not "opens java.net" to unnamed'
  • Loading branch information
OndraZizka authored Jun 22, 2023
1 parent 6039b20 commit dc17bf2
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/main/kotlin/khttp/requests/GenericRequest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,9 @@ class GenericRequest internal constructor(

private fun URL.toIDN(): URL {
val newHost = IDN.toASCII(this.host)
this.javaClass.getDeclaredField("host").apply { this.isAccessible = true }.set(this, newHost)
this.javaClass.getDeclaredField("authority").apply { this.isAccessible = true }.set(this, if (this.port == -1) this.host else "${this.host}:${this.port}")
val query = if (this.query == null) {
null
} else {
URLDecoder.decode(this.query, "UTF-8")
}
return URL(URI(this.protocol, this.userInfo, this.host, this.port, this.path, query, this.ref).toASCIIString())
val query = this.query ?. let { URLDecoder.decode(it, "UTF-8") }
return URL(URI(this.protocol, this.userInfo, newHost, this.port, this.path, query, this.ref).toASCIIString())
}

private fun makeRoute(route: String) = URL(route + if (this.params.isNotEmpty()) "?${Parameters(this.params)}" else "").toIDN().toString()

}

0 comments on commit dc17bf2

Please sign in to comment.