-
Notifications
You must be signed in to change notification settings - Fork 25
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
Chunk streaming request bodies only #157
Changes from 8 commits
e1787f1
e51c332
3122cb0
ad725d0
5ba026e
8489050
12f6c11
62dbaef
9f8a0c2
4f2531c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
import com.databricks.sdk.core.http.Request; | ||
import com.databricks.sdk.core.http.Response; | ||
import com.databricks.sdk.core.utils.CustomCloseInputStream; | ||
import com.databricks.sdk.mixin.ClustersExt; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.charset.StandardCharsets; | ||
|
@@ -21,11 +22,15 @@ | |
import org.apache.http.client.config.RequestConfig; | ||
import org.apache.http.client.methods.*; | ||
import org.apache.http.entity.InputStreamEntity; | ||
import org.apache.http.entity.StringEntity; | ||
import org.apache.http.impl.client.CloseableHttpClient; | ||
import org.apache.http.impl.client.HttpClientBuilder; | ||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class CommonsHttpClient implements HttpClient { | ||
private static final Logger LOG = LoggerFactory.getLogger(ClustersExt.class); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not ClustersExt, but CommonsHttpClient |
||
private final PoolingHttpClientConnectionManager connectionManager = | ||
new PoolingHttpClientConnectionManager(); | ||
private final CloseableHttpClient hc; | ||
|
@@ -117,18 +122,26 @@ private HttpUriRequest transformRequest(Request in) { | |
case Request.DELETE: | ||
return new HttpDelete(in.getUri()); | ||
case Request.POST: | ||
return withEntity(new HttpPost(in.getUri()), in.getBody()); | ||
return withEntity(new HttpPost(in.getUri()), in); | ||
case Request.PUT: | ||
return withEntity(new HttpPut(in.getUri()), in.getBody()); | ||
return withEntity(new HttpPut(in.getUri()), in); | ||
case Request.PATCH: | ||
return withEntity(new HttpPatch(in.getUri()), in.getBody()); | ||
return withEntity(new HttpPatch(in.getUri()), in); | ||
default: | ||
throw new IllegalArgumentException("Unknown method: " + in.getMethod()); | ||
} | ||
} | ||
|
||
private HttpRequestBase withEntity(HttpEntityEnclosingRequestBase request, InputStream body) { | ||
request.setEntity(new InputStreamEntity(body)); | ||
private HttpRequestBase withEntity(HttpEntityEnclosingRequestBase request, Request in) { | ||
if (in.isBodyString()) { | ||
request.setEntity(new StringEntity(in.getBodyString(), StandardCharsets.UTF_8)); | ||
} else if (in.isBodyStreaming()) { | ||
request.setEntity(new InputStreamEntity(in.getBodyStream())); | ||
} else { | ||
LOG.warn( | ||
"withEntity called with a request with no body, so no request entity will be set. URI: {}", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
in.getUri()); | ||
} | ||
return request; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This used to be
<InputStream>
; I've changed it to(streamed body)
in the debug log.