openai / openai/openai-java

Feat. Request: HttpRequest/HttpResponse convenience methods.

Open
#664 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement sdk
Dominant language
Kotlin
Stars
1.5k
Forks
264
Avg merge
9h 46m
Merged PRs (30d)
96

Description

Description

In order to implement the HttpClient interface in Java to embed a custom HttpClient in the SDK, there is the need to implement some ellaborate mapping for a few entities in the HttpRequest/HttpResponse.

1. Headers

Currently one can iterate through names and then get a List<String> for each. This results in code that looks like this:

HttpHeaders target = new HttpHeaders();
sourceHeaders.names().forEach(name -> {
    List<String> values = sourceHeaders.values(name);
    HttpHeaderName headerName = HttpHeaderName.fromString(name);
    if (values.isEmpty()) {
        target.set(headerName, "");
    } else {
        target.set(headerName, values);
    }
});
return target;

It would be nice to have something that returns the Headers as Map<String, String> or even Map<String, List<String>>

2. HttpResponseBody

Given the API, one has to "double read" the content of the body by calling fun writeTo(outputStream: OutputStream)

It would be nice to have an alternative that would return an java.io.InputStream so we can pipe the body directly to our type.

3. HttpRequestBody

Same as the above. Having the contents of the body returned as an InputStream would make things more ergonomic for us.

Thank you!

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

Locate the HttpHeaders, HttpRequestBody, and HttpResponseBody definitions, then inspect the existing names(), values(), and writeTo(OutputStream) APIs. Done means providing ergonomic header and InputStream access for request and response bodies while preserving the existing behavior; the issue does not name specific tests or files to run.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kotlin
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.