mirror of
https://github.com/wanghongenpin/proxypin.git
synced 2026-04-14 20:53:34 +08:00
Request edit records http request (#253)
This commit is contained in:
@@ -37,6 +37,8 @@ Future<void> main() async {
|
||||
|
||||
/// 代理服务器
|
||||
class ProxyServer {
|
||||
static ProxyServer? current;
|
||||
|
||||
//socket服务
|
||||
Server? server;
|
||||
|
||||
@@ -46,7 +48,9 @@ class ProxyServer {
|
||||
//配置
|
||||
final Configuration configuration;
|
||||
|
||||
ProxyServer(this.configuration);
|
||||
ProxyServer(this.configuration) {
|
||||
current = this;
|
||||
}
|
||||
|
||||
//是否启动
|
||||
bool get isRunning => server?.isRunning ?? false;
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:desktop_multi_window/desktop_multi_window.dart';
|
||||
import 'package:file_selector/file_selector.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:network_proxy/network/bin/server.dart';
|
||||
import 'package:network_proxy/network/components/request_rewrite_manager.dart';
|
||||
import 'package:network_proxy/network/components/script_manager.dart';
|
||||
import 'package:network_proxy/network/http/http.dart';
|
||||
@@ -144,6 +145,10 @@ void registerMethodHandler() {
|
||||
DesktopMultiWindow.setMethodHandler((call, fromWindowId) async {
|
||||
logger.d('${call.method} $fromWindowId ${call.arguments}');
|
||||
|
||||
if (call.method == 'getProxyInfo') {
|
||||
return ProxyServer.current?.isRunning == true ? {'host': '127.0.0.1', 'port': ProxyServer.current!.port} : null;
|
||||
}
|
||||
|
||||
if (call.method == 'refreshScript') {
|
||||
await ScriptManager.instance.then((value) {
|
||||
return value.reloadScript();
|
||||
|
||||
@@ -26,7 +26,7 @@ class AppConfiguration {
|
||||
Locale? _language;
|
||||
|
||||
//是否显示更新内容公告
|
||||
bool upgradeNoticeV10 = true;
|
||||
bool upgradeNoticeV12 = true;
|
||||
|
||||
/// 是否启用画中画
|
||||
ValueNotifier<bool> pipEnabled = ValueNotifier(true);
|
||||
@@ -37,8 +37,6 @@ class AppConfiguration {
|
||||
/// header默认展示
|
||||
bool headerExpanded = true;
|
||||
|
||||
bool? iosVpnBackgroundAudioEnable;
|
||||
|
||||
//桌面window大小
|
||||
Size? windowSize;
|
||||
|
||||
@@ -123,12 +121,11 @@ class AppConfiguration {
|
||||
var mode =
|
||||
ThemeMode.values.firstWhere((element) => element.name == config['mode'], orElse: () => ThemeMode.system);
|
||||
_theme = ThemeModel(mode: mode, useMaterial3: config['useMaterial3'] ?? true);
|
||||
upgradeNoticeV10 = config['upgradeNoticeV10'] ?? true;
|
||||
upgradeNoticeV12 = config['upgradeNoticeV12'] ?? true;
|
||||
_language = config['language'] == null ? null : Locale.fromSubtags(languageCode: config['language']);
|
||||
pipEnabled.value = config['pipEnabled'] ?? true;
|
||||
pipIcon.value = config['pipIcon'] ?? false;
|
||||
headerExpanded = config['headerExpanded'] ?? true;
|
||||
iosVpnBackgroundAudioEnable = config['iosVpnBackgroundAudioEnable'];
|
||||
|
||||
windowSize =
|
||||
config['windowSize'] == null ? null : Size(config['windowSize']['width'], config['windowSize']['height']);
|
||||
@@ -156,14 +153,13 @@ class AppConfiguration {
|
||||
return {
|
||||
'mode': _theme.mode.name,
|
||||
'useMaterial3': _theme.useMaterial3,
|
||||
'upgradeNoticeV10': upgradeNoticeV10,
|
||||
'upgradeNoticeV12': upgradeNoticeV12,
|
||||
"language": _language?.languageCode,
|
||||
'pipEnabled': pipEnabled.value,
|
||||
'pipIcon': pipIcon.value ? true : null,
|
||||
"headerExpanded": headerExpanded,
|
||||
"windowSize": windowSize == null ? null : {"width": windowSize?.width, "height": windowSize?.height},
|
||||
"windowPosition": windowPosition == null ? null : {"dx": windowPosition?.dx, "dy": windowPosition?.dy},
|
||||
"iosVpnBackgroundAudioEnable": iosVpnBackgroundAudioEnable == false ? null : iosVpnBackgroundAudioEnable
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +78,10 @@ class HttpBodyState extends State<HttpBodyWidget> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (widget.httpMessage == null) {
|
||||
return const SizedBox();
|
||||
}
|
||||
|
||||
if ((widget.httpMessage?.body == null || widget.httpMessage?.body?.isEmpty == true) &&
|
||||
widget.httpMessage?.messages.isNotEmpty == false) {
|
||||
return const SizedBox();
|
||||
@@ -85,7 +89,7 @@ class HttpBodyState extends State<HttpBodyWidget> {
|
||||
|
||||
var tabs = Tabs.of(widget.httpMessage?.contentType, isJsonText());
|
||||
|
||||
if (tabIndex >= tabs.list.length) tabIndex = tabs.list.length - 1;
|
||||
if (tabIndex > 0 && tabIndex >= tabs.list.length) tabIndex = tabs.list.length - 1;
|
||||
bodyKey.currentState?.changeState(widget.httpMessage, tabs.list[tabIndex]);
|
||||
|
||||
List<Widget> list = [
|
||||
|
||||
@@ -65,7 +65,7 @@ class _DesktopHomePagePageState extends State<DesktopHomePage> implements EventL
|
||||
proxyServer.addListener(this);
|
||||
panel = NetworkTabController(tabStyle: const TextStyle(fontSize: 16), proxyServer: proxyServer);
|
||||
|
||||
if (widget.appConfiguration.upgradeNoticeV10) {
|
||||
if (widget.appConfiguration.upgradeNoticeV12) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
showUpgradeNotice();
|
||||
});
|
||||
@@ -113,7 +113,7 @@ class _DesktopHomePagePageState extends State<DesktopHomePage> implements EventL
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
widget.appConfiguration.upgradeNoticeV10 = false;
|
||||
widget.appConfiguration.upgradeNoticeV12 = false;
|
||||
widget.appConfiguration.flushConfig();
|
||||
Navigator.pop(context);
|
||||
},
|
||||
|
||||
@@ -22,6 +22,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:flutter_toastr/flutter_toastr.dart';
|
||||
import 'package:network_proxy/network/host_port.dart';
|
||||
import 'package:network_proxy/network/http/http.dart';
|
||||
import 'package:network_proxy/network/http/http_headers.dart';
|
||||
import 'package:network_proxy/network/http_client.dart';
|
||||
@@ -141,16 +142,21 @@ class RequestEditorState extends State<RequestEditor> {
|
||||
var requestBody = requestKey.currentState?.getBody();
|
||||
String url = currentState.requestUrl.text;
|
||||
|
||||
HttpRequest request =
|
||||
HttpRequest(HttpMethod.valueOf(currentState.requestMethod), Uri.parse(url).toString());
|
||||
HttpRequest request = HttpRequest(HttpMethod.valueOf(currentState.requestMethod), Uri.parse(url).toString());
|
||||
request.headers.addAll(headers);
|
||||
request.body = requestBody == null ? null : utf8.encode(requestBody);
|
||||
|
||||
HttpClients.proxyRequest(request).then((response) {
|
||||
responseKey.currentState?.change(null);
|
||||
responseChange.value = !responseChange.value;
|
||||
|
||||
Map? proxyResult = await DesktopMultiWindow.invokeMethod(0, 'getProxyInfo');
|
||||
ProxyInfo? proxyInfo = proxyResult == null ? null : ProxyInfo.of(proxyResult['host'], proxyResult['port']);
|
||||
|
||||
HttpClients.proxyRequest(request, proxyInfo: proxyInfo).then((response) {
|
||||
FlutterToastr.show(localizations.requestSuccess, context);
|
||||
this.response = response;
|
||||
responseChange.value = !responseChange.value;
|
||||
responseKey.currentState?.change(response);
|
||||
responseChange.value = !responseChange.value;
|
||||
}).catchError((e) {
|
||||
FlutterToastr.show('${localizations.fail}$e', context);
|
||||
});
|
||||
@@ -256,10 +262,10 @@ class _HttpState extends State<_HttpWidget> {
|
||||
}
|
||||
}
|
||||
|
||||
change(HttpMessage message) {
|
||||
change(HttpMessage? message) {
|
||||
this.message = message;
|
||||
body?.text = message.bodyAsString;
|
||||
headerKey.currentState?.refreshParam(message.headers.getHeaders());
|
||||
body?.text = message?.bodyAsString ?? '';
|
||||
headerKey.currentState?.refreshParam(message?.headers.getHeaders());
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -131,7 +131,7 @@ class MobileHomeState extends State<MobileHomePage> implements EventListener, Li
|
||||
}
|
||||
});
|
||||
|
||||
if (widget.appConfiguration.upgradeNoticeV10) {
|
||||
if (widget.appConfiguration.upgradeNoticeV12) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
showUpgradeNotice();
|
||||
});
|
||||
@@ -237,7 +237,7 @@ class MobileHomeState extends State<MobileHomePage> implements EventListener, Li
|
||||
'4. fix script binary body convert;\n'
|
||||
'';
|
||||
showAlertDialog(isCN ? '更新内容V1.1.2' : "Update content V1.1.2", content, () {
|
||||
widget.appConfiguration.upgradeNoticeV10 = false;
|
||||
widget.appConfiguration.upgradeNoticeV12 = false;
|
||||
widget.appConfiguration.flushConfig();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:flutter_toastr/flutter_toastr.dart';
|
||||
import 'package:network_proxy/native/vpn.dart';
|
||||
import 'package:network_proxy/network/bin/server.dart';
|
||||
import 'package:network_proxy/network/host_port.dart';
|
||||
import 'package:network_proxy/network/http/http.dart';
|
||||
@@ -161,13 +160,17 @@ class RequestEditorState extends State<MobileRequestEditor> with SingleTickerPro
|
||||
request.body = requestBody == null ? null : utf8.encode(requestBody);
|
||||
|
||||
var proxyInfo =
|
||||
Vpn.isVpnStarted && widget.proxyServer != null ? ProxyInfo.of("127.0.0.1", widget.proxyServer?.port) : null;
|
||||
widget.proxyServer?.isRunning == true ? ProxyInfo.of("127.0.0.1", widget.proxyServer?.port) : null;
|
||||
|
||||
responseKey.currentState?.change(null);
|
||||
responseChange.value = !responseChange.value;
|
||||
|
||||
HttpClients.proxyRequest(proxyInfo: proxyInfo, request).then((response) {
|
||||
FlutterToastr.show(localizations.requestSuccess, context);
|
||||
this.response = response;
|
||||
this.response?.request = request;
|
||||
responseChange.value = !responseChange.value;
|
||||
responseKey.currentState?.change(response);
|
||||
responseChange.value = !responseChange.value;
|
||||
tabController.animateTo(1);
|
||||
}).catchError((e) {
|
||||
FlutterToastr.show('${localizations.fail}$e', context);
|
||||
@@ -231,10 +234,13 @@ class _HttpState extends State<_HttpWidget> with AutomaticKeepAliveClientMixin {
|
||||
}
|
||||
}
|
||||
|
||||
change(HttpMessage message) {
|
||||
change(HttpMessage? message) {
|
||||
this.message = message;
|
||||
body = message.bodyAsString;
|
||||
headerKey.currentState?.refreshParam(message.headers.getHeaders());
|
||||
body = message?.bodyAsString;
|
||||
headerKey.currentState?.refreshParam(message?.headers.getHeaders());
|
||||
setState(() {
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
HttpHeaders? getHeaders() {
|
||||
|
||||
Reference in New Issue
Block a user