Comments (14)
I think serialized name is still a bit foreign. I'd prefer calling it something like http_header_name.
header! {
rust_name = Foo;
http_header_name = "X-Foo";
repr = [String];
}
from reqwest.
Could you switch to the http create for headers?
The upcoming 0.9 release upgrades to hyper 0.12, which adds support for the http
crate. I'm working an upgrade for the typed headers as well, so each can pick how to deal with headers.
from reqwest.
It still would be nice, that reqwest reexported header! macro, as it is the only thing, why I directly have to depend on hyper.
I know! But macro_reexport
is an unstable feature, so it cannot be done on stable Rust. 😢
from reqwest.
That's a possibility. I wonder if it makes sense to copy verbatim, of if this is an opportunity to make the macro less confusing. Perhaps keywords in the macro instead of sigils would make things more clear?
header! {
name = "X-Foo";
type = Foo;
repr = [String]; // I don't know if Vec<String> would work, but if it would, maybe that's better?
}
from reqwest.
I like the key-value style of your suggestion,
although the choice of key "type" for the generated rust struct feels weird,
as it's not a preexisting type but something generated by the macro.
Alternatives quickly get verbose, f.ex with
header! {
rust_name = Foo;
serialized_name = "X-Foo";
repr = [String];
}
from reqwest.
@softprops assuming you're asking about current reqwest (0.8.x), you can make use of type inference, or use turbofish syntax:
let ty: ContentType = res.headers().get().unwrap();
let len = res.headers().get::<ContentLength>().unwrap;
from reqwest.
I went for raw_headers as opposed to the typed headers in an app which uses reqwest for now,
couldn't figure out how to merge the output of the header! macro from hyper with reqwest.
I'd be up for implementing this if someone could guide me in the correct direction (Is a copy-paste of the header macro the best solution?).
from reqwest.
This is how I used header! macro with reqwest
header! { (CustomAuthenticationHeader, "custom_auth") => [String] }
let http_client = reqwest::Client::new().unwrap();
let mut response = http_client.post(url)
.header(CustomAuthenticationHeader(api_key))
.body(body)
.send()
.unwrap();
It still would be nice, that reqwest reexported header! macro, as it is the only thing, why I directly have to depend on hyper.
from reqwest.
Could we as a stopgap measure til the feature becomes stable, re-implement the macro in the reqwest library?
from reqwest.
are there any examples for how to get a header? reqwest's header map takes a value argument and hypers takes a type argument.
from reqwest.
Sry I was mistaken. I was actually using the http crate which I thought reqwest used.
from reqwest.
Could you switch to the http
create for headers? It has HeaderName::from_str
.
The macros are enormous hassle. I also don't see how such type-strict solution could work with header names only known at run time (e.g. Vary
and Connection
can refer to arbitrary header names).
from reqwest.
@seanmonstar when doing it, are you also keeping support for the ByteRangeSpec
and others?
I ended doing a hackish solution for now, when upgrading to 0.9 release, but it is far from neat... :-(
from reqwest.
reqwest no longer has typed headers built in (could conceivably come back some day).
from reqwest.
Related Issues (20)
- How to implement different retry strategies?
- `brotli` feature doesn't work HOT 4
- Skip DNS resolution to connect to IP. HOT 3
- Help me understand the connection pool HOT 1
- Please avoid pulling in ring, it has a restrictive license that's incompatible with the GPL HOT 1
- cloud flare user-agent check failure (does not happen on web or curl) => format!("{agent}'") fixes this
- Error when parsing large JSON with `.json::<serde_json::Value>()` in wasm and Node.js 22 HOT 2
- redirect 307 Unable to return the correct webpage content properly HOT 1
- http1.1 upgrade doesn't work with rustls HOT 3
- Different behaviors in python and rust HOT 5
- HTTP/2 Client Only Allows 200 Concurrent Requests? HOT 4
- Allow DNS overrides per request
- HTTP/2 not working HOT 3
- RequestBuilder::header unsets `sensitive` on header value HOT 2
- How to add several custom CA certificate
- Do not consume response when reading body HOT 1
- Expose encoding of path fragment in public API HOT 2
- Regarding the problem of reqwest request timeout caused by using OpenVpn HOT 2
- Add a new crate feature `strip-url-in-error` HOT 3
- Add custom cookie to specific client.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reqwest.