All Projects → mrmike → Ok2curl

mrmike / Ok2curl

Licence: apache-2.0
Convert OkHttp requests into curl logs.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Ok2curl

okhttp-awssigner
An OkHttp interceptor for signing requests with AWSv4 signatures
Stars: ✭ 14 (-95.25%)
Mutual labels:  okhttp, interceptor
Chucker
🔎 An HTTP inspector for Android & OkHTTP (like Charles but on device)
Stars: ✭ 2,169 (+635.25%)
Mutual labels:  okhttp, interceptor
Logginginterceptor
An OkHttp interceptor which has pretty logger for request and response. +Mock support
Stars: ✭ 1,149 (+289.49%)
Mutual labels:  okhttp, interceptor
Xniffer
A swift network profiler built on top of URLSession.
Stars: ✭ 488 (+65.42%)
Mutual labels:  curl, interceptor
Androidhttp
Android Http网络开发神兵利器
Stars: ✭ 88 (-70.17%)
Mutual labels:  curl, okhttp
Okurl
OkHttp Kotlin command line
Stars: ✭ 77 (-73.9%)
Mutual labels:  curl, okhttp
Okhttp Json Mock
Mock your datas for Okhttp and Retrofit in json format in just a few moves
Stars: ✭ 231 (-21.69%)
Mutual labels:  okhttp, interceptor
OKHttpLogInterceptor
A Pretty OkHttp Logging Interceptor(一款简洁漂亮的OkHttp Logging拦截器)
Stars: ✭ 16 (-94.58%)
Mutual labels:  okhttp, interceptor
RetryRequestInterceptor-for-OkHttp
a interceptor for OkHttp which can save failed request in storage and will retry request until success or retry times over limit , or request live time over limit
Stars: ✭ 42 (-85.76%)
Mutual labels:  okhttp, interceptor
Cake.Curl
🍰↕️ A cross-platform add-in for Cake that allows to transfer files to and from remote URLs using curl.
Stars: ✭ 17 (-94.24%)
Mutual labels:  curl
Turbo
A lightweight microservice tool, turn your grpc|thrift APIs into HTTP APIs!
Stars: ✭ 275 (-6.78%)
Mutual labels:  interceptor
request-extra
⚡️ Extremely stable HTTP request module built on top of libcurl with retries, timeouts and callback API
Stars: ✭ 14 (-95.25%)
Mutual labels:  curl
wxapp-api-interceptors
微信小程序api拦截器
Stars: ✭ 99 (-66.44%)
Mutual labels:  interceptor
Fetch Intercept
Interceptor library for the native fetch command inspired by angular http intercepts.
Stars: ✭ 279 (-5.42%)
Mutual labels:  interceptor
Auto LFI
A simple Script which tests for LFI (Local File Inclusion) via Curl
Stars: ✭ 17 (-94.24%)
Mutual labels:  curl
Data Science At The Command Line
Data Science at the Command Line
Stars: ✭ 3,174 (+975.93%)
Mutual labels:  curl
MultiHttp
This is a high performance , very useful multi-curl tool written in php. 一个超级好用的并发CURL工具!!!(httpful,restful, concurrency)
Stars: ✭ 79 (-73.22%)
Mutual labels:  curl
yab
Call and benchmark YARPC services from the command line.
Stars: ✭ 66 (-77.63%)
Mutual labels:  curl
Curl To Php
Convert curl commands to PHP code in your browser
Stars: ✭ 292 (-1.02%)
Mutual labels:  curl
Watchtower
🗼Observe OKHttp API Calls With Request And Response Details Right In Your Browser!
Stars: ✭ 286 (-3.05%)
Mutual labels:  okhttp

Ok2Curl Build Status Android Arsenal Release

Convert OkHttp requests into curl logs.

Usage

Add library to project dependencies. Library is hosted on jcenter.

repositories {
    jcenter()
}

dependencies {
    implementation 'com.github.mrmike:ok2curl:0.7.0'
}

To start logging requests with Ok2Curl add interceptor to OkHttp client.

OkHttpClient okHttp = new OkHttpClient.Builder()
    .addInterceptor(new CurlInterceptor(new Loggable() {
            @Override
            public void log(String message) {
                Log.v("Ok2Curl", message);
            }
        }))
    .build();

Result

With Ok2Curl set up correctly every executed request will be transformed into curl log e.g.

adb logcat -s "Ok2Curl"
curl -X GET -H "Cache-Control:max-stale=2147483647, only-if-cached" https://api.github.com/repos/vmg/redcarpet/issues?state=closed

Network interceptors

By default Ok2Curl uses application interceptors from OkHttp which is adequate for most cases. But sometimes you may want to use network interceptor e.g. to log Cookies set via CookieHandler. In such a case add interceptor the same way as below:

OkHttpClient okHttp = new OkHttpClient.Builder()
    .addNetworkInterceptor(new CurlInterceptor())
    .build();

To get know more about Interceptor in OkHttp take a look here: https://github.com/square/okhttp/wiki/Interceptors

Header modifiers

Ok2Curl allows you to modify any header before creating curl command. All you have to do is create your own modifier that implements HeaderModifier and add this modifier to CurlInterceptor. See sample for reference.

final BasicAuthorizationHeaderModifier modifier = new BasicAuthorizationHeaderModifier(new Base64Decoder());
final List<HeaderModifier> modifiers = Collections.<HeaderModifier>singletonList(modifier);

final CurlInterceptor curlInterceptor = new CurlInterceptor(new AndroidLogger(), modifiers);

Options

Ok2Curl supports basic Curl options. In order to use options use the following code:

final Options options = Options.builder()
                .insecure()
                .connectTimeout(120)
                .retry(5)
                .build();

final CurlInterceptor interceptor = new CurlInterceptor(logger, options);

Since now every Curl command will start with curl --insecure --connect-timeout 120 --retry 5...

Supported options

  • --insecure
  • --max-time seconds
  • --connect-timeout seconds
  • --retry num
  • --compressed
  • --location

If would like to support any new options please feel free to open PR. Full list of curl options is available here.

License

Copyright 2018 Michał Moczulski

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].