1717 */
1818package org .jackhuang .hmcl .util .io ;
1919
20+ import org .glavo .url .WebURL ;
2021import org .jackhuang .hmcl .util .Pair ;
2122import org .jackhuang .hmcl .util .StringUtils ;
2223import org .jetbrains .annotations .NotNull ;
2324import org .jetbrains .annotations .Nullable ;
2425
2526import java .io .*;
2627import java .net .*;
27- import java .net .http .HttpClient ;
28- import java .net .http .HttpHeaders ;
29- import java .net .http .HttpResponse ;
3028import java .nio .charset .Charset ;
3129import java .util .*;
3230import java .util .Map .Entry ;
@@ -162,10 +160,10 @@ public static URI dropQuery(URI u) {
162160 }
163161 }
164162
165- public static URLConnection createConnection (URI uri ) throws IOException {
163+ public static URLConnection createConnection (WebURL url ) throws IOException {
166164 URLConnection connection ;
167165 try {
168- connection = uri .toURL ().openConnection ();
166+ connection = url .toURL ().openConnection ();
169167 } catch (IllegalArgumentException | MalformedURLException e ) {
170168 throw new IOException (e );
171169 }
@@ -179,8 +177,16 @@ public static URLConnection createConnection(URI uri) throws IOException {
179177 return connection ;
180178 }
181179
180+ public static URLConnection createConnection (URI uri ) throws IOException {
181+ return createConnection (WebURL .of (uri ));
182+ }
183+
184+ public static HttpURLConnection createHttpConnection (WebURL url ) throws IOException {
185+ return (HttpURLConnection ) createConnection (url );
186+ }
187+
182188 public static HttpURLConnection createHttpConnection (String url ) throws IOException {
183- return (HttpURLConnection ) createConnection (toURI (url ));
189+ return (HttpURLConnection ) createConnection (WebURL . parse (url ));
184190 }
185191
186192 public static HttpURLConnection createHttpConnection (URI url ) throws IOException {
@@ -436,24 +442,7 @@ public static String decodeURL(String toDecode) {
436442
437443 /// @throws IllegalArgumentException if the string is not a valid URI
438444 public static @ NotNull URI toURI (@ NotNull String uri ) {
439- try {
440- return new URI (encodeLocation (uri ));
441- } catch (URISyntaxException e ) {
442- // Possibly an Internationalized Domain Name (IDN)
443- return URI .create (uri );
444- }
445- }
446-
447- public static @ NotNull URI toURI (@ NotNull URL url ) {
448- return toURI (url .toExternalForm ());
449- }
450-
451- public static @ NotNull HttpResponse .ResponseInfo getResponseInfo (@ NotNull HttpResponse <?> response ) {
452- record ResponseInfoImpl (int statusCode , HttpHeaders headers , HttpClient .Version version )
453- implements HttpResponse .ResponseInfo {
454- }
455-
456- return new ResponseInfoImpl (response .statusCode (), response .headers (), response .version ());
445+ return WebURL .toURI (uri );
457446 }
458447
459448 public static @ Nullable URI toURIOrNull (String uri ) {
0 commit comments