Commit deb92db
refactor: move away from legacy
* refactor: move away from legacy `hyper::body::HttpBody`
this is an incremental step away from hyper 0.14's request and response
body interfaces, and towards the 1.0 body types. see
<linkerd/linkerd2#8733> for more information
about upgrading to hyper 1.0.
hyper 0.14 provides a `hyper::body::Body` that is removed in the 1.0
interface. `hyper-util` now provides a workable default body type. hyper
0.14 reëxports `http_body::Body` as `HttpBody`. hyper 1.0 reëxports this
trait as `hyper::body::Body` without any renaming.
this commit moves application code away from hyper's legacy `Body` type
and the `HttpBody` trait alias. this commit moves assorted interfaces
towards the boxed `BoxBody` type instead. when possible, code is tweaked
such that it refers to the reëxport in `linkerd-proxy-http`, rather than
directly through `hyper`.
NB: this commit is based upon #3466.
Signed-off-by: katelyn martin <[email protected]>
* feat(http/box): `BoxBody::from_static` constructor
this commit relates to review feedback offered here:
#3467 (comment)
it is slightly ungainly to place a static string into a BoxBody,
something that is a fairly common pattern throughout e.g. our admin
server.
to help nudge the compiler to infer a `B: Body` of `String`, various
code follows a common convention of calling e.g.
`BoxBody::new::<String>("ready\n".into())` or,
`BoxBody::new("ready\n".to_string())`.
this commit helps reduce that boilerplate by adding a `from_static(..)`
constructor that accepts a static string.
```rust
/// Returns a [`BoxBody`] with the contents of a static string.
pub fn from_static(body: &'static str) -> Self {
Self::new(body.to_string())
}
```
Co-authored-by: Scott Fleener <[email protected]>
Signed-off-by: katelyn martin <[email protected]>
* refactor(app/admin): outline json bytes body construction
see <#3467 (comment)>.
@sfleen points out this unfortunate part of our diff:
```diff
- .body(json.into())
+ .body(BoxBody::new(http_body::Full::new(bytes::Bytes::from(json))))
```
this *is* a bit of an unfortunate edge, where boxing up a body feels
especially cumbersome.
this commit takes an attempt at tweaking the function in question so
that this large nested expression reads a bit nicer.
first, to justify why this gets a little more involved: hyper will no
longer provide the `Body` type after 1.0, so we are tasked with
providing our own body. for our purposes, `Full` works because we have a
single chunk of bytes in hand.
in order to create a `Full`, we must provide a `D: Buf`, which can be
satisfied by the following types:
<https://docs.rs/bytes/1.6.0/bytes/buf/trait.Buf.html#foreign-impls>
most simply, we can cast our vector of bytes into a `Bytes`.
with all of this in hand, we can hoist this creation of the body up out
of the `match` arm, and use `Result::map` to apply these constructors in
sequential order:
```rust
// Serialize the value into JSON, and then place the bytes in a boxed response body.
let json = serde_json::to_vec(val)
.map(Bytes::from)
.map(http_body::Full::new)
.map(BoxBody::new);
```
Signed-off-by: katelyn martin <[email protected]>
---------
Signed-off-by: katelyn martin <[email protected]>
Co-authored-by: Scott Fleener <[email protected]>hyper::body::HttpBody (#3467)1 parent 35e7316 commit deb92db
File tree
45 files changed
+202
-172
lines changed- hyper-balance
- src
- linkerd
- app
- admin
- src
- server
- log
- core/src/errors
- gateway/src/http
- inbound/src
- http
- policy
- integration/src
- outbound/src
- http
- logical
- policy/route/metrics
- tests
- policy
- src/trace_collector
- http
- box/src
- upgrade/src
- metrics
- src
- opencensus/src
- opentelemetry/src
- proxy
- http/src
- server
- spire-client/src
- tap
- src
- grpc
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
45 files changed
+202
-172
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
969 | 969 | | |
970 | 970 | | |
971 | 971 | | |
| 972 | + | |
972 | 973 | | |
973 | 974 | | |
974 | 975 | | |
| |||
1312 | 1313 | | |
1313 | 1314 | | |
1314 | 1315 | | |
| 1316 | + | |
1315 | 1317 | | |
1316 | 1318 | | |
1317 | 1319 | | |
| |||
1999 | 2001 | | |
2000 | 2002 | | |
2001 | 2003 | | |
| 2004 | + | |
2002 | 2005 | | |
| 2006 | + | |
2003 | 2007 | | |
2004 | 2008 | | |
2005 | 2009 | | |
| |||
2335 | 2339 | | |
2336 | 2340 | | |
2337 | 2341 | | |
| 2342 | + | |
2338 | 2343 | | |
2339 | 2344 | | |
| 2345 | + | |
2340 | 2346 | | |
2341 | 2347 | | |
2342 | 2348 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
| 62 | + | |
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
| 83 | + | |
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
93 | | - | |
| 93 | + | |
94 | 94 | | |
95 | | - | |
| 95 | + | |
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
141 | | - | |
| 141 | + | |
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
151 | | - | |
| 151 | + | |
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
| |||
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
201 | | - | |
| 201 | + | |
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
| |||
429 | 429 | | |
430 | 430 | | |
431 | 431 | | |
432 | | - | |
| 432 | + | |
433 | 433 | | |
434 | 434 | | |
435 | 435 | | |
| |||
456 | 456 | | |
457 | 457 | | |
458 | 458 | | |
459 | | - | |
| 459 | + | |
460 | 460 | | |
461 | 461 | | |
462 | 462 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | 15 | | |
20 | 16 | | |
21 | | - | |
| 17 | + | |
22 | 18 | | |
23 | 19 | | |
24 | 20 | | |
| |||
45 | 41 | | |
46 | 42 | | |
47 | 43 | | |
48 | | - | |
| 44 | + | |
49 | 45 | | |
50 | 46 | | |
51 | 47 | | |
| |||
73 | 69 | | |
74 | 70 | | |
75 | 71 | | |
76 | | - | |
| 72 | + | |
77 | 73 | | |
78 | 74 | | |
79 | 75 | | |
80 | 76 | | |
81 | | - | |
| 77 | + | |
82 | 78 | | |
83 | 79 | | |
84 | 80 | | |
85 | 81 | | |
86 | | - | |
| 82 | + | |
87 | 83 | | |
88 | 84 | | |
89 | 85 | | |
90 | 86 | | |
91 | | - | |
| 87 | + | |
92 | 88 | | |
93 | 89 | | |
94 | 90 | | |
95 | | - | |
| 91 | + | |
96 | 92 | | |
97 | 93 | | |
98 | 94 | | |
99 | | - | |
| 95 | + | |
100 | 96 | | |
101 | 97 | | |
102 | 98 | | |
| |||
142 | 138 | | |
143 | 139 | | |
144 | 140 | | |
145 | | - | |
| 141 | + | |
146 | 142 | | |
147 | 143 | | |
148 | 144 | | |
149 | 145 | | |
150 | | - | |
| 146 | + | |
151 | 147 | | |
152 | 148 | | |
153 | 149 | | |
154 | 150 | | |
155 | 151 | | |
156 | 152 | | |
157 | | - | |
| 153 | + | |
158 | 154 | | |
159 | 155 | | |
160 | 156 | | |
161 | 157 | | |
162 | 158 | | |
163 | | - | |
| 159 | + | |
164 | 160 | | |
165 | 161 | | |
166 | 162 | | |
167 | 163 | | |
168 | | - | |
| 164 | + | |
169 | 165 | | |
170 | 166 | | |
171 | 167 | | |
172 | | - | |
| 168 | + | |
173 | 169 | | |
174 | 170 | | |
175 | 171 | | |
176 | | - | |
| 172 | + | |
177 | 173 | | |
178 | 174 | | |
179 | | - | |
| 175 | + | |
180 | 176 | | |
181 | 177 | | |
182 | 178 | | |
183 | | - | |
| 179 | + | |
184 | 180 | | |
185 | 181 | | |
186 | | - | |
| 182 | + | |
187 | 183 | | |
188 | 184 | | |
189 | 185 | | |
190 | | - | |
| 186 | + | |
191 | 187 | | |
192 | 188 | | |
193 | 189 | | |
194 | | - | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
195 | 193 | | |
196 | 194 | | |
197 | 195 | | |
| |||
215 | 213 | | |
216 | 214 | | |
217 | 215 | | |
218 | | - | |
| 216 | + | |
219 | 217 | | |
220 | 218 | | |
221 | 219 | | |
222 | | - | |
| 220 | + | |
223 | 221 | | |
224 | 222 | | |
225 | 223 | | |
| |||
331 | 329 | | |
332 | 330 | | |
333 | 331 | | |
334 | | - | |
| 332 | + | |
335 | 333 | | |
336 | 334 | | |
337 | 335 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | | - | |
| 7 | + | |
7 | 8 | | |
| 9 | + | |
| 10 | + | |
8 | 11 | | |
9 | 12 | | |
10 | 13 | | |
11 | | - | |
| 14 | + | |
12 | 15 | | |
13 | 16 | | |
14 | 17 | | |
| |||
18 | 21 | | |
19 | 22 | | |
20 | 23 | | |
21 | | - | |
| 24 | + | |
22 | 25 | | |
23 | 26 | | |
24 | 27 | | |
25 | | - | |
| 28 | + | |
| 29 | + | |
26 | 30 | | |
27 | 31 | | |
28 | 32 | | |
| |||
41 | 45 | | |
42 | 46 | | |
43 | 47 | | |
44 | | - | |
| 48 | + | |
45 | 49 | | |
46 | 50 | | |
47 | 51 | | |
48 | 52 | | |
49 | 53 | | |
50 | 54 | | |
51 | 55 | | |
52 | | - | |
53 | | - | |
54 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
55 | 65 | | |
56 | 66 | | |
57 | | - | |
| 67 | + | |
58 | 68 | | |
59 | 69 | | |
60 | 70 | | |
61 | 71 | | |
62 | 72 | | |
63 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
64 | 76 | | |
65 | 77 | | |
66 | 78 | | |
| |||
0 commit comments