You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently the typical way to insert a single header into a RequestBuilder is something like (e.g., Range header):
let request = client
.get(file_url).header(RANGE,format!("bytes={offset}-"));letmut response = request.send().await?;
I recently discovered the awesome headers crate and wanted to replace the string formatting with something strongly typed. However, there doesn't currently exist a direct way to plug something that implements Header.
But to me, the intermediate steps start to diminish the utility of RequestBuilder (at least, since there's only one custom header to insert). Another workaround would be to build the Request, and then add to its internal HeaderMap:
but this somewhat feels like Request is doing the job really meant for RequestBuilder.
Ideally, reqwest provides a RequestBuilder::typed_header to directly insert a impl Header instance. Alternatively, headers could expose something like RequestBuilderExt, similar to HeaderMapExt. Although, that might well go beyond the intended scope of headers.
Are there any other solutions that I may have missed? I'm happy to submit a PR for what ever path is most agreeable.
Thank you for reqwest (and headers)!
The text was updated successfully, but these errors were encountered:
I don't disagree, it would be very cool! I just am not sure about making reqwest depend on headers publicly. Then breaking changes in headers means we have to break reqwest too.
@jmagnuson thanks for that second solution, that saves an allocation, did not even think of that!
@seanmonstar a way to expose this without adding a dependency and without altering the current internal structure of holding a Result in the RequestBuilder would be to add a
Currently the typical way to insert a single header into a
RequestBuilder
is something like (e.g.,Range
header):I recently discovered the awesome
headers
crate and wanted to replace the string formatting with something strongly typed. However, there doesn't currently exist a direct way to plug something that implementsHeader
.One workaround is to construct a
HeaderMap
, for whichheaders::HeaderMapExt::typed_insert
exists:But to me, the intermediate steps start to diminish the utility of
RequestBuilder
(at least, since there's only one custom header to insert). Another workaround would be to build theRequest
, and then add to its internalHeaderMap
:but this somewhat feels like
Request
is doing the job really meant forRequestBuilder
.Ideally,
reqwest
provides aRequestBuilder::typed_header
to directly insert aimpl Header
instance. Alternatively,headers
could expose something likeRequestBuilderExt
, similar toHeaderMapExt
. Although, that might well go beyond the intended scope ofheaders
.Are there any other solutions that I may have missed? I'm happy to submit a PR for what ever path is most agreeable.
Thank you for
reqwest
(andheaders
)!The text was updated successfully, but these errors were encountered: