Commit 6b92a5a
authored
Chunk streaming request bodies only (#157)
## Changes
#138 changed the CommonsHttpClient implementation to use
`InputStreamEntity` for all request bodies sent using the Java SDK. As a
result, requests are sent with a `Transfer-Encoding: chunked` header,
and the request body is chunked accordingly. However, the Databricks
REST API only tolerates chunked requests for certain APIs; for others,
it ignores the request body if Content-Length is not specified. Auth
falls under that category, which caused #154.
To fix this, Request will keep track of string entities and input stream
entities separately. Previously, Request had separate fields for the
body and debugBody, but they were both always set, so it wasn't possible
to distinguish between these two cases. Now, HTTP clients can have
different behavior based on whether the request body can be fully
materialized as a string or is lazily read as with input streams.
As part of this, I have removed `SimpleHttpServer`. This was used before
we were sure whether it was possible to use the HttpServer built into
the JDK. Now that we are confident that we can (see usage in
ExternalBrowserCredentialsProvider.java), I've replaced it with
HttpServer and a custom HttpHandler in FixtureServer (the only place
where it is used now).
One other small change: I've updated the logging configuration and
dependency for the cli auth demo app. This ensures that users can see
debug output (which I used when debugging this).
Closes #154.
## Tests
I've refactored FixtureServer to support more advanced validation on the
HTTP requests sent by clients for testing purposes. Now, users can
assert that a request has a specific method, path, headers, body, and
check for headers that should not be present.
One downside of this change is that users need to call the `.with()`
method once per API call, rather than one time, at the start of each
test.
Unit tests cover both cases (request body should be chunked when
specified as a String; request body should not be chunked when specified
as an InputStream).1 parent 00052d4 commit 6b92a5a
11 files changed
Lines changed: 346 additions & 238 deletions
File tree
- databricks-sdk-java/src
- main/java/com/databricks/sdk/core
- commons
- http
- test/java/com/databricks/sdk/core
- commons
- http
- oauth
- examples/cli-auth-demo
- src/main/resources
Lines changed: 12 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | 15 | | |
17 | 16 | | |
18 | | - | |
19 | 17 | | |
20 | 18 | | |
21 | 19 | | |
| |||
187 | 185 | | |
188 | 186 | | |
189 | 187 | | |
190 | | - | |
191 | | - | |
| 188 | + | |
192 | 189 | | |
193 | | - | |
194 | | - | |
195 | | - | |
| 190 | + | |
| 191 | + | |
196 | 192 | | |
197 | 193 | | |
198 | 194 | | |
| |||
303 | 299 | | |
304 | 300 | | |
305 | 301 | | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
311 | 311 | | |
312 | 312 | | |
313 | 313 | | |
| |||
Lines changed: 0 additions & 108 deletions
This file was deleted.
Lines changed: 17 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| 28 | + | |
| 29 | + | |
27 | 30 | | |
28 | 31 | | |
| 32 | + | |
29 | 33 | | |
30 | 34 | | |
31 | 35 | | |
| |||
117 | 121 | | |
118 | 122 | | |
119 | 123 | | |
120 | | - | |
| 124 | + | |
121 | 125 | | |
122 | | - | |
| 126 | + | |
123 | 127 | | |
124 | | - | |
| 128 | + | |
125 | 129 | | |
126 | 130 | | |
127 | 131 | | |
128 | 132 | | |
129 | 133 | | |
130 | | - | |
131 | | - | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
132 | 144 | | |
133 | 145 | | |
134 | 146 | | |
Lines changed: 51 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
| |||
19 | 18 | | |
20 | 19 | | |
21 | 20 | | |
22 | | - | |
23 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
24 | 41 | | |
25 | 42 | | |
26 | | - | |
| 43 | + | |
27 | 44 | | |
28 | 45 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
| 46 | + | |
| 47 | + | |
35 | 48 | | |
36 | 49 | | |
37 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
38 | 59 | | |
39 | 60 | | |
40 | | - | |
41 | | - | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
42 | 65 | | |
43 | 66 | | |
44 | 67 | | |
| |||
135 | 158 | | |
136 | 159 | | |
137 | 160 | | |
138 | | - | |
139 | | - | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
140 | 171 | | |
141 | 172 | | |
142 | | - | |
143 | | - | |
| 173 | + | |
| 174 | + | |
144 | 175 | | |
145 | 176 | | |
146 | 177 | | |
| |||
151 | 182 | | |
152 | 183 | | |
153 | 184 | | |
154 | | - | |
| 185 | + | |
155 | 186 | | |
156 | 187 | | |
157 | 188 | | |
158 | 189 | | |
159 | | - | |
| 190 | + | |
160 | 191 | | |
161 | 192 | | |
162 | | - | |
| 193 | + | |
163 | 194 | | |
164 | 195 | | |
165 | 196 | | |
| |||
0 commit comments