proxyhttp 0.0.2 copy "proxyhttp: ^0.0.2" to clipboard
proxyhttp: ^0.0.2 copied to clipboard

PlatformAndroid

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 :

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

0
likes
135
points
230
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin project aim to proxy http(currently no https) traffic.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, http, http_parser, logger, plugin_platform_interface, shelf

More

Packages that depend on proxyhttp

Packages that implement proxyhttp