Skip to content

Commit 310b49d

Browse files
authored
Merge pull request #504 from DanXi-Dev/fix-webvpn-relative-url
Fix webvpn relative URL
2 parents ba4e9e6 + a78bc22 commit 310b49d

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/util/io/dio_utils.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class DioUtils {
8282
if (location != null) {
8383
if (location.isEmpty) return response;
8484
if (!Uri.parse(location).isAbsolute) {
85-
location = '${response.requestOptions.uri.origin}/$location';
85+
location = '${response.requestOptions.uri.origin}$location';
8686
}
8787
return processRedirect(dio,
8888
await dio.get(location, options: NON_REDIRECT_OPTION_WITH_FORM_TYPE));

lib/util/webvpn_proxy.dart

+21-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,26 @@ class WebvpnProxy {
9191
return true;
9292
}
9393

94-
if (response.realUri.toString().startsWith(WEBVPN_LOGIN_URL)) {
94+
/// Get the absolute final URL of the response (after all redirects).
95+
///
96+
/// [response.realUri] is not always the final URL, because it may be a relative URL (i.e., /login).
97+
String getAbsoluteFinalURL(Response<dynamic> response) {
98+
final realUri = response.realUri;
99+
if (realUri.isAbsolute) return realUri.toString();
100+
101+
// find the real origin in the reverse order
102+
for (final redirect in response.redirects.reversed) {
103+
if (redirect.location.isAbsolute) {
104+
return redirect.location.origin + realUri.toString();
105+
}
106+
}
107+
108+
return response.requestOptions.uri.origin + realUri.toString();
109+
}
110+
111+
final finalUrl = getAbsoluteFinalURL(response);
112+
debugPrint("Response URL: $finalUrl");
113+
if (finalUrl.startsWith(WEBVPN_LOGIN_URL)) {
95114
return true;
96115
}
97116

@@ -137,6 +156,7 @@ class WebvpnProxy {
137156
// Temporary cookie jar
138157
IndependentCookieJar workJar = IndependentCookieJar();
139158
newDio.interceptors.add(CookieManager(workJar));
159+
newDio.interceptors.add(DioLogInterceptor());
140160

141161
loginSession = _authenticateWebVPN(newDio, workJar, _personInfo);
142162
await loginSession;

0 commit comments

Comments
 (0)