-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
Configuration to disable Expect Header being set by default #303
Comments
On further digging, I see that the code has specific handling for this case. However, shouldn't that line be pushing If this is correct, then I can create a PR with a fix. |
I see that using I guess then a different extension function to disable default curl behaviour would make sense. |
Thank you for filing an issue! This does sound like something we should let you configure. Since we try to abstract away some of curl's unusual APIs, we don't expose this directly and right now there is no way to say, "Don't send this header". Most users would expect a call like Curl's
Unsetting a header is a weird operation that you probably don't normally need to do, since most automatically populated headers are usually done so for a good reason (of course, you can remove previously added user-defined headers via
This is the direction I would go: offer an explicit function to be able to control the behavior. That way we can avoid curl's "stringly-typed" way of doing it and prefer a more Rusty API. This is probably a good opportunity to allow you to control pub trait Configurable {
// ...
fn expect_100<T>(self, expect: T) -> Self
where
T: Into<Expect100>;
}
pub struct Expect100 {
timeout: Option<Duration>,
}
impl Expect100 {
pub const fn disabled() -> Self {
Self { timeout: None }
}
pub const fn enabled() -> Self {
Self {
timeout: Some(Duration::from_secs(1)), // default timeout
}
}
pub fn with_timeout<T>(timeout: T) -> Self
where
T: Into<Duration>
{
Self {
timeout: Some(timeout.into())
}
}
}
impl Default for Expect100 {
pub fn default() -> Self {
Self::enabled()
}
}
impl From<bool> for Expect100 {
fn from(value: bool) -> Self {
if value {
Self::enabled()
} else {
Self::disabled()
}
}
} Using it might look like: Request::post("/")
.expect_100(true) // default
.expect_100(false) // don't want it
.expect_100(Expect100::with_timeout(Duration::from_millis(100))) // keep it, but don't wait so long
.body(bytes)?
.send()? |
Thanks for the quick reply! My early thoughts around this (like in this commit) are roughly along the same line of what you proposed. Counter-intuitively, I'm finding that turning off the I'm actually building a http latency analysis tool similar to httpstat but to track behaviour across multiple requests with connection re-use. I set it up to make multiple requests with connection re-use and alternate between enabling and disabling the
where Thanks for the tip with I'll create a PR once I have this odd behaviour figured out. |
@sagebind Forgive the naive questions since I'm still learning about the Rust ecosystem. I'd like to use the new method introduced in Do I need to wait for |
No problem, I like questions. And welcome to Rust! You'll need to wait for a new release since Isahc uses only released versions of dependencies. Indeed, Crates.io does not allow you to publish crates that depend on anything other than other published crates on Crates.io. It's a quality control thing, among other reasons. I also happen to be a maintainer of curl-rust 😉 so I can probably have a new release published this week to be used here. For now, you can also work on developing this feature now by changing [dependencies]
crossbeam-utils = "0.8"
-curl = "0.4.34"
-curl-sys = "0.4.37"
+curl = { git = "https://github.com/alexcrichton/curl-rust" }
+curl-sys = { git = "https://github.com/alexcrichton/curl-rust" }
futures-lite = "1.11"
http = "0.2.1" Of course we can't merge your PR in this state, but at least it can be worked on. |
@sagebind Thanks for the reply. I had already switched to using local path and then git references to unblock myself. Everything seems to work fine when compiling with Anyways, I'll plod along and get back to this topic when a new upstream version becomes available. |
Both support for |
`curl 0.4.35` added the option to configure the timeout value that `curl` will wait for when using an `Expect` header before sending the request body. This commit adds the ability to configure this timeout via the `Configurable` trait within `isahc`. Fixes sagebind#303
`curl 0.4.35` added the option to configure the timeout value that `curl` will wait for when using an `Expect` header before sending the request body. This commit adds the ability to configure this timeout via the `Configurable` trait within `isahc`. Fixes sagebind#303
This can now be configured in the 1.5.0 release! |
Thanks a lot for this library!
I'm learning many Rust idioms from reading the code.
libcurl
sets theExpect: 100-continue
header by default for POST requests whose body exceeds a certain size. This leads to two round-trips to the server and so worse performance. This blog post describes the issue and a possible solution.I see that curl-rust sets the
CURLOPT_HTTPHEADER
but I can't figure out how to invoke thehttp_headers
method with parameters in the shape thatlibcurl
expects ie:Expect:
I tried setting an empty
Expect
header.header("Expect", "")
but this does not seem to deactivate thecurl
behaviour and leads to the server rejecting the request with a417 Expectation Failed
I tried setting the header as
.header("Expect:", "")
but this leads to ahttp::Error(InvalidHeaderName)
Any suggestions on how to set this header to disable the
libcurl
behaviour?Thanks in advance!
The text was updated successfully, but these errors were encountered: