twilio / twilio/twilio-java

[BUG] NetworkHttpClient RequestConfig overridden in makeRequest method

Open
#913 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

type: bug
Dominant language
Java
Stars
527
Forks
453
Avg merge
10h 59m
Merged PRs (30d)
6

Description

Describe the bug

The Twilio SDK allows its users to set different RequestConfig by including code like:

    RequestConfig config =
        RequestConfig.custom()
            .setConnectionRequestTimeout(Timeout.ofMilliseconds(connectionRequestTimeout))
            .setResponseTimeout(Timeout.ofMilliseconds(responseTimeout))
            .setConnectionKeepAlive(Timeout.ofMilliseconds(connectionKeepAlive))
            .build();
    NetworkHttpClient httpClient = new NetworkHttpClient(config);
    TwilioRestClient client =
        new TwilioRestClient.Builder(accountSid, authToken).httpClient(httpClient).build();
    Twilio.setRestClient(client);

However, this gets overriden by the request later in
https://github.com/twilio/twilio-java/blob/main/src/main/java/com/twilio/http/NetworkHttpClient.java#L136
So it doesn't allow users to set their own timeouts.

This makes the previous RequestConfig pointless. It would be better to remove the code snippet that sets the RequestConfig for the HttpUriRequestBase in

public Response makeRequest(final Request request)  {
...
}
Code snippet

https://github.com/twilio/twilio-java/blob/main/src/main/java/com/twilio/http/NetworkHttpClient.java#L136
httpUriRequestBase.setConfig(DEFAULT_REQUEST_CONFIG);

Actual behavior

RequestConfig set on NetworkHttpClient gets overriden by the request later in
https://github.com/twilio/twilio-java/blob/main/src/main/java/com/twilio/http/NetworkHttpClient.java#L136
So it doesn't allow users to set their own timeouts.

Expected behavior

Remove the code snippet that sets the RequestConfig for the HttpUriRequestBase in

public Response makeRequest(final Request request)  {
...
}

so users can use their own RequestConfig

twilio-java version

11.0.1

Java version

21.0.1-amzn

Logs or error messages

No response

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read src/main/java/com/twilio/http/NetworkHttpClient.java and inspect makeRequest, especially the setConfig call around line 136. Remove the request-level override so the RequestConfig supplied to NetworkHttpClient controls the request timeouts, then verify that custom connection, response, and keep-alive settings are honored.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.