-
Notifications
You must be signed in to change notification settings - Fork 869
使用 WebURL for Java 解析 URI #6084
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c131c57
使用 WebURL for Java 替换自定义 URI 解析逻辑
Glavo 0a2da34
Use WebURL.parseBrowserInput for URI creation
Glavo 89ed03b
Refactor URI handling to use WebURL for improved parsing and connecti…
Glavo 8eb4085
Remove unused HttpClient and response handling code from NetworkUtils
Glavo 23d122d
Use WebURL.parseBrowserInputToURI for background image URL loading
Glavo a76042a
Add WebURL for Java dependency to about page
Glavo 200780e
Remove unused import for NetworkUtils in AccountListPage
Glavo ad7f35b
Update loadImage method to accept WebURL for improved URL handling
Glavo 8566237
Refactor URL handling in AccountListPage to use NetworkUtils for impr…
Glavo 0f213ef
Remove unused import for WebURL in AccountListPage and AuthlibInjecto…
Glavo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,16 +17,14 @@ | |
| */ | ||
| package org.jackhuang.hmcl.util.io; | ||
|
|
||
| import org.glavo.url.WebURL; | ||
| import org.jackhuang.hmcl.util.Pair; | ||
| import org.jackhuang.hmcl.util.StringUtils; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| import java.io.*; | ||
| import java.net.*; | ||
| import java.net.http.HttpClient; | ||
| import java.net.http.HttpHeaders; | ||
| import java.net.http.HttpResponse; | ||
| import java.nio.charset.Charset; | ||
| import java.util.*; | ||
| import java.util.Map.Entry; | ||
|
|
@@ -162,10 +160,10 @@ public static URI dropQuery(URI u) { | |
| } | ||
| } | ||
|
|
||
| public static URLConnection createConnection(URI uri) throws IOException { | ||
| public static URLConnection createConnection(WebURL url) throws IOException { | ||
| URLConnection connection; | ||
| try { | ||
| connection = uri.toURL().openConnection(); | ||
| connection = url.toURL().openConnection(); | ||
| } catch (IllegalArgumentException | MalformedURLException e) { | ||
| throw new IOException(e); | ||
| } | ||
|
|
@@ -179,8 +177,16 @@ public static URLConnection createConnection(URI uri) throws IOException { | |
| return connection; | ||
| } | ||
|
|
||
| public static URLConnection createConnection(URI uri) throws IOException { | ||
| return createConnection(WebURL.of(uri)); | ||
| } | ||
|
|
||
| public static HttpURLConnection createHttpConnection(WebURL url) throws IOException { | ||
| return (HttpURLConnection) createConnection(url); | ||
| } | ||
|
|
||
| public static HttpURLConnection createHttpConnection(String url) throws IOException { | ||
| return (HttpURLConnection) createConnection(toURI(url)); | ||
| return (HttpURLConnection) createConnection(WebURL.parse(url)); | ||
| } | ||
|
|
||
| public static HttpURLConnection createHttpConnection(URI url) throws IOException { | ||
|
|
@@ -436,24 +442,7 @@ public static String decodeURL(String toDecode) { | |
|
|
||
| /// @throws IllegalArgumentException if the string is not a valid URI | ||
| public static @NotNull URI toURI(@NotNull String uri) { | ||
| try { | ||
| return new URI(encodeLocation(uri)); | ||
| } catch (URISyntaxException e) { | ||
| // Possibly an Internationalized Domain Name (IDN) | ||
| return URI.create(uri); | ||
| } | ||
| } | ||
|
|
||
| public static @NotNull URI toURI(@NotNull URL url) { | ||
| return toURI(url.toExternalForm()); | ||
| } | ||
|
|
||
| public static @NotNull HttpResponse.ResponseInfo getResponseInfo(@NotNull HttpResponse<?> response) { | ||
| record ResponseInfoImpl(int statusCode, HttpHeaders headers, HttpClient.Version version) | ||
| implements HttpResponse.ResponseInfo { | ||
| } | ||
|
|
||
| return new ResponseInfoImpl(response.statusCode(), response.headers(), response.version()); | ||
| return WebURL.toURI(uri); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
|
||
| public static @Nullable URI toURIOrNull(String uri) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
根据 PR 描述,
WebURL库支持宽松解析模式(parseBrowserInput),这更适合处理用户输入的 URL(例如自动补全协议)。为了与AuthlibInjectorServer和DecoratorController中的改动保持一致,建议在这里也使用WebURL.parseBrowserInput(url)而不是严格的WebURL.parse(url),以提高对各种输入格式的兼容性。