Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rafagan/fbc0e9a100d63d682647b735fae10fa0 to your computer and use it in GitHub Desktop.
Save rafagan/fbc0e9a100d63d682647b735fae10fa0 to your computer and use it in GitHub Desktop.
class CurlInterceptor extends Interceptor {
@override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
try {
final qp = options.queryParameters;
final h = options.headers;
final d = options.data;
final curl =
'curl -X ${options.method} \'${options.baseUrl}${options.path}' +
(qp.length != 0 ? qp.keys.fold('', (value, key) => '$value${value.length == 0 ? '?' : '&'}$key=${qp[key]}\'') : '\'') +
h.keys.fold('', (value, key) => '$value -H \'$key: ${h[key]}\'') +
(d.length != 0 ? ' --data-binary \'$d\'' : '') +
' --insecure';
print('server_curl: $curl');
} catch(e) {
print('CurlInterceptor error: $e');
}
super.onRequest(options, handler);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment