Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable builder #55

Merged
merged 2 commits into from Jan 24, 2021
Merged

Configurable builder #55

merged 2 commits into from Jan 24, 2021

Conversation

flocsy
Copy link
Contributor

@flocsy flocsy commented Nov 10, 2019

To enable creating custom CurlBuilders (for https://github.com/mrmike/Ok2Curl/issues)

public static class MyCurlInterceptor extends CurlInterceptor {
    private static final int[] PARTS_ORDER = new int[]{
            ConfigurableCurlBuilder.PART_CURL,
            ConfigurableCurlBuilder.PART_OPTIONS,
            ConfigurableCurlBuilder.PART_METHOD,
            ConfigurableCurlBuilder.PART_URL,
            ConfigurableCurlBuilder.PART_BODY,
            ConfigurableCurlBuilder.PART_CONTENT_TYPE,
            ConfigurableCurlBuilder.PART_HEADERS
    };

    public MyCurlInterceptor(Loggable logger) {
        super(logger);
    }

    @Override
    protected CurlBuilder getCurlBuilder(Request copy) {
        return new ConfigurableCurlBuilder(copy, limit, headerModifiers, options, delimiter, PARTS_ORDER);
    }
}

Let me know what do you think. I think it can also be merged into CurlBuilder, since we have a default order so we can move all the code in ConfigurableCurlBuilder into CurlBuilder

@C2H6O
Copy link

C2H6O commented Dec 7, 2020

@flocsy any reason not to merge this in?

@flocsy
Copy link
Contributor Author

flocsy commented Dec 7, 2020

you can merge IMHO

@mrmike
Copy link
Owner

mrmike commented Jan 24, 2021

LGTM 👍

@mrmike mrmike merged commit 1866a4c into mrmike:master Jan 24, 2021
@mrmike mrmike mentioned this pull request Jan 24, 2021
@sergeidyga
Copy link

@mrmike As far as I understand ConfigurableCurlBuilder is not used in CurlInterceptor constructor now. If so - why it exist?

@mrmike
Copy link
Owner

mrmike commented Oct 18, 2021

Hi @sergeidyga,

You can create your custom Interceptor and override method getCurlBuilder() to return getCurlBuilder. Let's take a look on example from the first post

public static class MyCurlInterceptor extends CurlInterceptor {
    private static final int[] PARTS_ORDER = new int[]{
            ConfigurableCurlBuilder.PART_CURL,
            ConfigurableCurlBuilder.PART_OPTIONS,
            ConfigurableCurlBuilder.PART_METHOD,
            ConfigurableCurlBuilder.PART_URL,
            ConfigurableCurlBuilder.PART_BODY,
            ConfigurableCurlBuilder.PART_CONTENT_TYPE,
            ConfigurableCurlBuilder.PART_HEADERS
    };

    public MyCurlInterceptor(Loggable logger) {
        super(logger);
    }

    @Override
    protected CurlBuilder getCurlBuilder(Request copy) {
        return new ConfigurableCurlBuilder(copy, limit, headerModifiers, options, delimiter, PARTS_ORDER);
    }
}

If you have any more questions I'll be happy to answer them :)

Thanks
Michał

@sergeidyga
Copy link

Hi Michał! Thank you for your explanation 🙂 now I see.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants