Skip to content

Skip adding default content-type header 'application/x-www-form-urlencoded' if content is null #1083

Description

@karthik-119

Dear ScribeJava,

Library: https://github.com/scribejava/scribejava/tree/master/scribejava-httpclient-apache

While building the request object:

I would like to ask you add a condition while adding the default 'Content-Type' header while preparing the requests, to verify the entity and if it's null then skip adding default 'Content-Type' header

private <T> Future<T> doExecuteAsync(String userAgent, Map<String, String> headers, Verb httpVerb,
            String completeUrl, HttpEntity entity, OAuthAsyncRequestCallback<T> callback,
            OAuthRequest.ResponseConverter<T> converter) {
        final RequestBuilder builder = getRequestBuilder(httpVerb);
        builder.setUri(completeUrl);

        if (entity != null && httpVerb.isPermitBody()) {
            if (!headers.containsKey(CONTENT_TYPE)) {
                builder.addHeader(CONTENT_TYPE, DEFAULT_CONTENT_TYPE);
            }
            builder.setEntity(entity);
        }

just like the implementation of OkHttpClient lib:

if (bodyContents != null && HttpMethod.permitsRequestBody(method)) {
.

I agree with your reasoning from #966, that you want to allow the possibilities. On the other hand, few servers are too strict that they don't accept other kinds of 'Content-Type' that they don't support.

If you still want to keep the behavior same, I would like to understand the reasoning behind a different implementation for OkHttpClient.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions