Skip to content

Commit

Permalink
修复详情请求重写填充域名错误问题,请求编辑重发响应体查看增加多种格式,详情Body体增加快速解码入口
Browse files Browse the repository at this point in the history
  • Loading branch information
wanghongenpin committed Aug 31, 2023
1 parent b748aa6 commit 26857ec
Show file tree
Hide file tree
Showing 21 changed files with 253 additions and 149 deletions.
7 changes: 5 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,15 @@ Widget multiWindow(int windowId, Map<dynamic, dynamic> argument) {
return HttpBodyWidget(
windowController: WindowController.fromWindowId(windowId),
httpMessage: HttpMessage.fromJson(argument['httpMessage']),
inNewWindow: true);
inNewWindow: true,
hideRequestRewrite: true);
}

if (argument['name'] == 'EncoderWidget') {
return EncoderWidget(
type: EncoderType.nameOf(argument['type']), windowController: WindowController.fromWindowId(windowId));
type: EncoderType.nameOf(argument['type']),
text: argument['text'],
windowController: WindowController.fromWindowId(windowId));
}

return const SizedBox();
Expand Down
10 changes: 7 additions & 3 deletions lib/network/http/http.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,15 @@ class HttpRequest extends HttpMessage {

String get requestUrl => uri.startsWith("/") ? '${remoteDomain()}$uri' : uri;

String? path() {
if (hostAndPort?.isSsl() == true && uri.startsWith("/")) {
return uri;
Uri? get requestUri {
try {
return Uri.parse(requestUrl);
} catch (e) {
return null;
}
}

String? path() {
try {
var requestPath = Uri.parse(requestUrl).path;
return requestPath.isEmpty ? "/" : requestPath;
Expand Down
2 changes: 1 addition & 1 deletion lib/network/http/http_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:network_proxy/network/http/http_headers.dart';

/// http解析器
class HttpParse {
static const int defaultMaxLength = 40960;
static const int defaultMaxLength = 102400;

/// 解析请求行
List<String> parseInitialLine(ByteBuf data, int size) {
Expand Down
30 changes: 28 additions & 2 deletions lib/network/util/system_proxy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:io';

import 'package:network_proxy/network/host_port.dart';
import 'package:network_proxy/utils/ip.dart';
import 'package:network_proxy/utils/lang.dart';
import 'package:proxy_manager/proxy_manager.dart';

/// @author wanghongen
Expand All @@ -10,11 +11,13 @@ class SystemProxy {
static String? _hardwarePort;

///获取系统代理
static Future<ProxyInfo?> getSystemProxy(ProxyTypes proxyTypes) async {
static Future<ProxyInfo?> getSystemProxy(ProxyTypes types) async {
if (Platform.isWindows) {
return await _getSystemProxyWindows();
} else if (Platform.isMacOS) {
return await _getSystemProxyMacOS(proxyTypes);
return await _getSystemProxyMacOS(types);
} else if (Platform.isLinux) {
return await _getLinuxProxyServer(types);
} else {
return null;
}
Expand Down Expand Up @@ -198,6 +201,29 @@ class SystemProxy {
]).then((results) => results.stdout.toString());
}

static Future<ProxyInfo?> _getLinuxProxyServer(ProxyTypes types) async {
///linux 获取代理
var mode = await Process.run("gsettings", ["get", "org.gnome.system.proxy", "mode"])
.then((value) => value.stdout.toString().trim());
if (mode.contains("manual")) {
var hostFuture = Process.run("gsettings", ["get", "org.gnome.system.proxy.${types.name}", "host"])
.then((value) => value.stdout.toString().trim());
var portFuture = Process.run("gsettings", ["get", "org.gnome.system.proxy.${types.name}", "port"])
.then((value) => value.stdout.toString().trim());

return Future.wait([hostFuture, portFuture]).then((value) {
print(value);
var host = Strings.trimWrap(value[0], "'");
var port = Strings.trimWrap(value[1], "'");
if (host.isNotEmpty && port.isNotEmpty) {
return ProxyInfo.of(host, int.parse(port));
}
return null;
});
}
return null;
}

static _concatCommands(List<String> commands) {
return commands.where((element) => element.isNotEmpty).join(' && ');
}
Expand Down
20 changes: 16 additions & 4 deletions lib/ui/component/encoder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ enum EncoderType {
class EncoderWidget extends StatefulWidget {
final EncoderType type;
final WindowController? windowController;
final String? text;

const EncoderWidget({super.key, required this.type, this.windowController});
const EncoderWidget({super.key, required this.type, this.windowController, this.text});

@override
State<EncoderWidget> createState() => _EncoderState();
Expand All @@ -47,6 +48,8 @@ class _EncoderState extends State<EncoderWidget> with SingleTickerProviderStateM
void initState() {
super.initState();
type = widget.type;
inputText = widget.text ?? '';

tabController = TabController(initialIndex: type.index, length: tabs.length, vsync: this);
RawKeyboard.instance.addListener(onKeyEvent);
}
Expand All @@ -71,7 +74,7 @@ class _EncoderState extends State<EncoderWidget> with SingleTickerProviderStateM
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: true,
resizeToAvoidBottomInset: true,
appBar: AppBar(
title: Text('${type.name.toUpperCase()}编码', style: const TextStyle(fontSize: 16)),
centerTitle: true,
Expand All @@ -91,7 +94,8 @@ class _EncoderState extends State<EncoderWidget> with SingleTickerProviderStateM
children: <Widget>[
const Text('输入要转换的内容'),
const SizedBox(height: 5),
TextField(
TextFormField(
initialValue: inputText,
minLines: 5,
maxLines: 10,
onChanged: (text) => inputText = text,
Expand All @@ -107,7 +111,15 @@ class _EncoderState extends State<EncoderWidget> with SingleTickerProviderStateM
const SizedBox(width: 50),
type == EncoderType.md5
? const SizedBox()
: OutlinedButton(onPressed: decode, child: Text('${type.name.toUpperCase()}解码')),
: FilledButton(onPressed: decode, child: Text('${type.name.toUpperCase()}解码')),
const SizedBox(width: 50),
OutlinedButton(
onPressed: () {
setState(() {
outputTextController.clear();
});
},
child: const Text('清空结果')),
],
),
const Text('转换结果'),
Expand Down
29 changes: 29 additions & 0 deletions lib/ui/component/multi_window.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'dart:convert';
import 'dart:io';

import 'package:desktop_multi_window/desktop_multi_window.dart';
import 'package:flutter/material.dart';
import 'package:network_proxy/ui/component/encoder.dart';
import 'package:network_proxy/utils/platform.dart';
import 'package:window_manager/window_manager.dart';

encodeWindow(EncoderType type, BuildContext context, [String? text]) async {
if (Platforms.isMobile()) {
Navigator.of(context).push(MaterialPageRoute(builder: (context) => EncoderWidget(type: type, text: text)));
return;
}

var ratio = 1.0;
if (Platform.isWindows) {
ratio = WindowManager.instance.getDevicePixelRatio();
}

final window = await DesktopMultiWindow.createWindow(jsonEncode(
{'name': 'EncoderWidget', 'type': type.name, 'text': text},
));
window.setTitle('编码');
window
..setFrame(const Offset(80, 80) & Size(900 * ratio, 600 * ratio))
..center()
..show();
}
34 changes: 19 additions & 15 deletions lib/ui/component/state_component.dart
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
import 'package:flutter/material.dart';
import 'package:flutter/material.dart';

class StateComponent extends StatefulWidget {
class KeepAliveWrapper extends StatefulWidget {
const KeepAliveWrapper({Key? key, this.keepAlive = true, required this.child}) : super(key: key);
final bool keepAlive;
final Widget child;
final Function? onChange;

const StateComponent(this.child, {Key? key, this.onChange }) : super(key: key);

@override
State<StatefulWidget> createState() {
return _StateComponentState();
}
State<KeepAliveWrapper> createState() => _KeepAliveWrapperState();
}

class _StateComponentState extends State<StateComponent> {
void changeState() {
setState(() {});
if (widget.onChange != null) {
widget.onChange!();
}
}
class _KeepAliveWrapperState extends State<KeepAliveWrapper> with AutomaticKeepAliveClientMixin {
@override
Widget build(BuildContext context) {
super.build(context);
return widget.child;
}

@override
void didUpdateWidget(covariant KeepAliveWrapper oldWidget) {
if (oldWidget.keepAlive != widget.keepAlive) {
// keepAlive 状态需要更新,实现在 AutomaticKeepAliveClientMixin 中
updateKeepAlive();
}
super.didUpdateWidget(oldWidget);
}

@override
bool get wantKeepAlive => widget.keepAlive;
}
30 changes: 5 additions & 25 deletions lib/ui/component/toolbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:desktop_multi_window/desktop_multi_window.dart';
import 'package:flutter/material.dart';
import 'package:network_proxy/network/bin/server.dart';
import 'package:network_proxy/ui/component/encoder.dart';
import 'package:network_proxy/ui/component/multi_window.dart';
import 'package:network_proxy/ui/mobile/request/request_editor.dart';
import 'package:network_proxy/utils/platform.dart';
import 'package:window_manager/window_manager.dart';
Expand Down Expand Up @@ -34,28 +35,28 @@ class _ToolboxState extends State<Toolbox> {
onTap: httpRequest,
child: Container(
padding: const EdgeInsets.all(10),
child: const Column(children: [Icon(Icons.http), Text('发起请求')]),
child: const Column(children: [Icon(Icons.http), Text('发起请求', style: TextStyle(fontSize: 14))]),
)),
const Divider(thickness: 0.3),
const Text('编码', style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold)),
Row(
children: [
InkWell(
onTap: () => encode(EncoderType.url),
onTap: () => encodeWindow(EncoderType.url, context),
child: Container(
padding: const EdgeInsets.all(10),
child: const Column(children: [Icon(Icons.link), Text(' URL')]),
)),
const SizedBox(width: 10),
InkWell(
onTap: () => encode(EncoderType.base64),
onTap: () => encodeWindow(EncoderType.base64, context),
child: Container(
padding: const EdgeInsets.all(10),
child: const Column(children: [Icon(Icons.currency_bitcoin), Text('Base64')]),
)),
const SizedBox(width: 15),
InkWell(
onTap: () => encode(EncoderType.md5),
onTap: () => encodeWindow(EncoderType.md5, context),
child: Container(
padding: const EdgeInsets.all(10),
child: const Column(children: [Icon(Icons.enhanced_encryption), Text('MD5')]),
Expand All @@ -67,27 +68,6 @@ class _ToolboxState extends State<Toolbox> {
);
}

encode(EncoderType type) async {
if (Platforms.isMobile()) {
Navigator.of(context).push(MaterialPageRoute(builder: (context) => EncoderWidget(type: type)));
return;
}

var ratio = 1.0;
if (Platform.isWindows) {
ratio = WindowManager.instance.getDevicePixelRatio();
}

final window = await DesktopMultiWindow.createWindow(jsonEncode(
{'name': 'EncoderWidget', 'type': type.name},
));
window.setTitle('编码');
window
..setFrame(const Offset(80, 80) & Size(900 * ratio, 600 * ratio))
..center()
..show();
}

httpRequest() async {
if (Platforms.isMobile()) {
Navigator.of(context)
Expand Down
Loading

0 comments on commit 26857ec

Please sign in to comment.