proxyhttp 0.0.2
proxyhttp: ^0.0.2 copied to clipboard
A Flutter plugin project aim to proxy http(currently no https) traffic.
proxyhttp #
A Flutter plugin project aim to proxy http(currently no https) traffic
Dependencies #
Using :
- xray core android lib wrapped by v2rayNG
- hev-socks5-tunnel transporting tun traffic to socks5
How to Use #
implements HttpInterceptor #
class TestHttpInterceptor implements HttpInterceptor{
@override
Future<bool> onRequest(http.Request request) async {
return false;
}
@override
Future<bool> onResponse(http.Response response) async {
final originalBody = response.bodyBytes;
String? contentEncoding = response.headers['content-encoding']?.trim().toLowerCase();
List<int> uncompressedBody;
if (contentEncoding == 'gzip') {
uncompressedBody = gzip.decode(originalBody);
} else if (contentEncoding == 'deflate') {
uncompressedBody = zlib.decode(originalBody);
} else {
uncompressedBody = originalBody;
}
final statusLine = 'HTTP/1.1 ${response.statusCode} ${response.reasonPhrase ?? ''}\r\n';
final headersString = response.headers.entries
.map((e) => '${e.key}: ${e.value}\r\n')
.join('');
final endOfHeaders = '\r\n';
final head = utf8.encode(statusLine + headersString + endOfHeaders);
final r = Uint8List.fromList([...head, ...uncompressedBody]);
print('response: ${HttpProxyServer.extractUnicodeCharacters(r)} ');
return false;
}
}
start local server #
_server = HttpProxyServer(port:"9000-9003").withInterceptor(TestHttpInterceptor());
await _server.start();
register plugin #
MainActivity.kts
class MainActivity : FlutterActivity(){
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if(requestCode == ProxyHttpVpn.Companion.VPN_START_CODE){
if (resultCode == RESULT_OK) {
activity.startService(ProxyHttpVpn.startVpnIntent(activity))
return
}
}
}
/**
* register plugin
*/
private fun pluginRegister(flutterEngine: FlutterEngine) {
flutterEngine.plugins.add(ProxyhttpPlugin())
}
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
pluginRegister(flutterEngine)
}
}
request vpn permission #
AndroidManifest.xml
<application
<---/>
<service
android:name="com.fan.proxyhttp.vpn.ProxyHttpVpn"
android:exported="true"
android:permission="android.permission.BIND_VPN_SERVICE">
<intent-filter>
<action android:name="andorid.net.VpnService" />
</intent-filter>
</service>
<---/>
</application>
start vpn #
_proxyhttpPlugin.startVpn(proxyPort: _serverPort);
you can look example for detail