Coder Social home page Coder Social logo

ok2curl's People

Contributors

flocsy avatar friederbluemle avatar jacek-marchwicki avatar mirland avatar mrmike avatar paour avatar swankjesse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ok2curl's Issues

Tips: not work for okhttp_3.x version

System.err:
Caused by: java.lang.ClassCastException: okhttp3.Headers cannot be cast to java.lang.Iterable

Because of:
okhttp3.Headers will extends Iterable until after okttp_4.x.

Maybe need add to README.

Escape `"` in the the headers

From backend I'm receiving a header like this: etag: "estoesunapruebadeetag" the " are part of the etag.

OkHttp when I call this endpoint again it adds this header: If-None-Match: "estoesunapruebadeetag".

But on curl I see this: -H "If-None-Match:"estoesunapruebadeetag"" when it should be -H "If-None-Match:\"estoesunapruebadeetag\"". The " should be escaped.

Cookies added by CookieHandler don't show up as headers in the ok2curl-output

In an app I bridge cookies between the WebView and okhttp. This is done by setting a cookie-handler on the okhttp-client. These cookies, however, do not show up as headers in the requests that are printed.

example cookie handler & request (httpbin here simply echos the cookies it receives).

public class Ok2CurlCookieDemo {

    static final String tag = "Ok2CurlCookieDemo";

    private Ok2CurlCookieDemo() {
    }

    public static class FooBarCookieHandler extends CookieHandler {

        @Override
        public Map<String, List<String>> get(final URI uri, final Map<String, List<String>> requestHeaders) throws IOException {
            final Map<String, List<String>> result = Maps.newHashMap();
            final ArrayList<String> value = Lists.newArrayList("foo=bar; banana=rama;");
            result.put("Cookie", value);
            return result;
        }

        @Override
        public void put(final URI uri, final Map<String, List<String>> responseHeaders) throws IOException {

        }
    }

    public static void doRequest() {

        final OkHttpClient okHttpClient = new OkHttpClient();

        okHttpClient.setCookieHandler(new FooBarCookieHandler());
        Ok2Curl.set(okHttpClient);

        okHttpClient
                .newCall(new Request.Builder().url("http://httpbin.org/cookies").build())
                .enqueue(new Callback() {
                    @Override
                    public void onFailure(final Request request, final IOException e) {

                    }

                    @Override
                    public void onResponse(final Response response) throws IOException {
                        Log.d(tag, "httpbin got cookies: " +  response.body().string());
                    }
                });
    }
}

outputs:

10-16 10:39:49.350 1586-1608/? D/Ok2Curl: curl -X GET http://httpbin.org/cookies
10-16 10:39:49.556 1586-1608/? D/Ok2CurlCookieDemo: httpbin got cookies: {
10-16 10:39:49.556 1586-1608/? D/Ok2CurlCookieDemo:   "cookies": {
10-16 10:39:49.556 1586-1608/? D/Ok2CurlCookieDemo:     "banana": "rama", 
10-16 10:39:49.556 1586-1608/? D/Ok2CurlCookieDemo:     "foo": "bar"
10-16 10:39:49.556 1586-1608/? D/Ok2CurlCookieDemo:   }
10-16 10:39:49.556 1586-1608/? D/Ok2CurlCookieDemo: }

Recognize Basic Authorization

In case request contains Authorization header of Basic type, e.g.,

Authorizaton: Basic bWFjaWVrOnRham5laGFzbG8xMjM=

would it be possible to have the following

curl -u maciej:tajnehaslo123 ...

?

Missing from Jcenter

I cannot find the repo in jcenter, I tried this url and it looks like it's missing. Is it available on it? I'm using jitpack and it's working fine.

I saw that the remote was changed in this commit 10a27fc

Invalid handling of multiple headers of same name

My request is having two headers of the same name:

Cookie: JSESSIONID=....
Cookie: SOMETOKEN=....; OTHERTOKEN=....

This is correct with respect to HTTP protocol. However, CurlBuilder will take only the last header, because it is using a map with unique keys for header names:

    public CurlBuilder(Request request, long limit) {
       ...

        final Headers headers = request.headers();
        for (int i = 0; i < headers.size(); i++) {
            \\ MG: If there was already a header with same name it will be overwritten here
            this.headers.put(headers.name(i), headers.value(i));
        }
    }

unable to build

I'm not able to sync gradle.

Error:Dependency com.github.mrmike:ok2curl:0.2.0 on project app resolves to an APK archive which is not supported as a compilation dependency.

NPE when calling MediaType.toString()

I just got this error:

10-13 12:08:27.317 1889-1912/? E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
10-13 12:08:27.317 1889-1912/? E/AndroidRuntime: Process: my.package.name, PID: 1889
10-13 12:08:27.317 1889-1912/? E/AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.squareup.okhttp.MediaType.toString()' on a null object reference
10-13 12:08:27.317 1889-1912/? E/AndroidRuntime:     at com.moczul.ok2curl.CurlBuilder.<init>(CurlBuilder.java:35)
10-13 12:08:27.317 1889-1912/? E/AndroidRuntime:     at com.moczul.ok2curl.CurlInterceptor.intercept(CurlInterceptor.java:31)
10-13 12:08:27.317 1889-1912/? E/AndroidRuntime:     at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:221)
10-13 12:08:27.317 1889-1912/? E/AndroidRuntime:     at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:195)
10-13 12:08:27.317 1889-1912/? E/AndroidRuntime:     at com.squareup.okhttp.Call.access$100(Call.java:34)
10-13 12:08:27.317 1889-1912/? E/AndroidRuntime:     at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:162)
10-13 12:08:27.317 1889-1912/? E/AndroidRuntime:     at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)
10-13 12:08:27.317 1889-1912/? E/AndroidRuntime:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
10-13 12:08:27.317 1889-1912/? E/AndroidRuntime:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
10-13 12:08:27.317 1889-1912/? E/AndroidRuntime:     at java.lang.Thread.run(Thread.java:818)

I used OkHttp Version 2.5 and Ok2Curl 0.0.2.

HTTP request body should not be URL encoded

For the following HTTP Request:

POST https://iamakamai.sqaextranet.akamai.com/ids-sso-config/restricted/idp/reminders http/1.1
Content-Type: application/x-www-form-urlencoded
INFO: Content-Length: 54
when=2017-09-26T14%3A20%3A19.425%2B02%3A00&force=false

Ok2Curl logs invalid curl command:

Ok2Curl: curl -X POST -H "Content-Type:application/x-www-form-urlencoded" -H "Content-Length:54" -H "Host:" -H "Accept-Encoding:gzip" -H "User-Agent:okhttp/3.8.0" -d 'when=2017-09-26T14%3A17%3A57.823%2B02%3A00&force=false'  https://server.com/reminders 

It is invalid because the HTTP request body under "-d" is already URL encoded. It should not be, because curl will encode it anyway.

Put URL and body before headers

Hi and thanks for the lib,

I'm using this lib in my project to have HTTP calls logged and be able to reproduce them and import them in Postman. It works great !
But it's quite hard to find the call we are looking for because every request log start with the same text :

curl -X GET -H "Authorization:Bearer <a very looonnngg token>" -H "<some more headers>: <some more headers values>" "https://<the url we are looking for>"

So we are still using a "standard" OkHttp logger to get the URL readable easily.

Would it be possible to change the order of arguments in the curl command to :

  • the method
  • the url
  • the body
  • headers

Ex :
curl -X GET "https://example.com/endpoint" -d "a body" -H "header1: foo" -H "header2: bar"

v0.2.4 - broken build

after upgrading from v0.2.3 to v0.2.4

...
:app:transformClassesWithDexForLiveDebug
Dex: Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.
    UNEXPECTED TOP-LEVEL EXCEPTION:
    java.lang.RuntimeException: Exception parsing classes
        at com.android.dx.command.dexer.Main.processClass(Main.java:761)
        at com.android.dx.command.dexer.Main.processFileBytes(Main.java:727)
        at com.android.dx.command.dexer.Main.access$1200(Main.java:87)
        at com.android.dx.command.dexer.Main$FileBytesConsumer.processFileBytes(Main.java:1655)
        at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
        at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
        at com.android.dx.command.dexer.Main.processOne(Main.java:681)
        at com.android.dx.command.dexer.Main.processAllFiles(Main.java:578)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:315)
        at com.android.dx.command.dexer.Main.run(Main.java:286)
        at com.android.builder.internal.compiler.DexWrapper.run(DexWrapper.java:52)
        at com.android.builder.core.AndroidBuilder$2.call(AndroidBuilder.java:1511)
        at com.android.builder.core.AndroidBuilder$2.call(AndroidBuilder.java:1507)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)
    Caused by: com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
        at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
        at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
        at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
        at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
        at com.android.dx.command.dexer.Main.parseClass(Main.java:773)
        at com.android.dx.command.dexer.Main.access$1600(Main.java:87)
        at com.android.dx.command.dexer.Main$ClassParserTask.call(Main.java:1694)
        at com.android.dx.command.dexer.Main.processClass(Main.java:758)
        ... 17 more

1 error; aborting
:app:transformClassesWithDexForLiveDebug FAILED

I have only one module (android application)

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.