Skip to content

http-types and async-h1 2.0.0 #520

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

Merged
merged 6 commits into from
May 22, 2020
Merged

Conversation

jbr
Copy link
Member

@jbr jbr commented May 19, 2020

A few notes on this mostly-find-and-replace PR:

  • This is building against async-h1 update for http-types 2.0.0 async-h1#105 and http-types master, as there are not yet releases for those

  • This PR revealed an issue with surf's native client when talking to a server that understands 100-continue. instead of attempting to resolve that, this pr switches to surf's async-h1 client for testing. Problem with Expect: 100-continue handling with isahc surf#177 represents further work required to address this

  • Interacting with a single header value is still a little awkward and this PR is inconsistent about using [0] vs HeaderValues::last()

  • It's surprising that Response::append_header panics if the ToHeaderValues cannot be converted but Response::set_header does not

  • Tests that rely on surf are still a little awkward because of incompatible http-types

  • An unexpected side effect of accepting TryIntourl::Url for http_types::Request is that they can no longer be constructed with an implicit url::Url as in "str".parse().unwrap(), but instead need to be explicitly parsed as url::Url::parse("str").unwrap(). I was surprised to discover that Url isn't TryFrom<&str>.

@jbr jbr requested a review from yoshuawuyts May 19, 2020 21:27
@jbr jbr force-pushed the update-http-types branch from 3564484 to 87cb9e9 Compare May 19, 2020 23:11
@Fishrock123
Copy link
Member

Fishrock123 commented May 19, 2020

I've updated tide-compress to this (see branch), which was fairly painless and pretty nice, but now my tests have some kind of failure here when calling async_h1::client::connect: https://github.com/Fishrock123/tide-compress/blob/17f6783114a9948027e53e9e48170bd44e37042b/tests/compressed.rs#L120

thread 'async-std/executor' panicked at 'Empty response', <::std::macros::panic macros>:2:4
stack backtrace:
   0: backtrace::backtrace::trace_unsynchronized
             at C:\Users\VssAdministrator\.cargo\registry\src\github.com-1ecc6299db9ec823\backtrace-0.3.44\src\backtrace\mod.rs:66
   1: std::sys_common::backtrace::_print_fmt
             at /rustc/4fb7144ed159f94491249e86d5bbd033b5d60550\/src\libstd\sys_common\backtrace.rs:78
   2: std::sys_common::backtrace::_print::{{impl}}::fmt
             at /rustc/4fb7144ed159f94491249e86d5bbd033b5d60550\/src\libstd\sys_common\backtrace.rs:59
   3: core::fmt::write
             at /rustc/4fb7144ed159f94491249e86d5bbd033b5d60550\/src\libcore\fmt\mod.rs:1063
   4: std::io::Write::write_fmt<std::sys::windows::stdio::Stderr>
             at /rustc/4fb7144ed159f94491249e86d5bbd033b5d60550\/src\libstd\io\mod.rs:1426
   5: std::sys_common::backtrace::_print
             at /rustc/4fb7144ed159f94491249e86d5bbd033b5d60550\/src\libstd\sys_common\backtrace.rs:62
   6: std::sys_common::backtrace::print
             at /rustc/4fb7144ed159f94491249e86d5bbd033b5d60550\/src\libstd\sys_common\backtrace.rs:49
   7: std::panicking::default_hook::{{closure}}
             at /rustc/4fb7144ed159f94491249e86d5bbd033b5d60550\/src\libstd\panicking.rs:204
   8: std::panicking::default_hook
             at /rustc/4fb7144ed159f94491249e86d5bbd033b5d60550\/src\libstd\panicking.rs:224
   9: std::panicking::rust_panic_with_hook
             at /rustc/4fb7144ed159f94491249e86d5bbd033b5d60550\/src\libstd\panicking.rs:470
  10: std::panicking::begin_panic<str*>
             at /rustc/4fb7144ed159f94491249e86d5bbd033b5d60550\src\libstd\panicking.rs:397
  11: async_h1::client::decode::decode::{{closure}}<async_std::net::tcp::stream::TcpStream>
             at <::std::macros::panic macros>:2
  12: std::future::{{impl}}::poll<generator-0>
             at /rustc/4fb7144ed159f94491249e86d5bbd033b5d60550\src\libstd\future.rs:44
  13: std::future::poll_with_tls_context<std::future::GenFuture<generator-0>>
             at /rustc/4fb7144ed159f94491249e86d5bbd033b5d60550\src\libstd\future.rs:102
  14: async_h1::client::connect::{{closure}}<async_std::net::tcp::stream::TcpStream>
             at C:\Users\Jeremiah\.cargo\git\checkouts\async-h1-04a36e89250b9764\d26570a\src\client\mod.rs:22
  15: std::future::{{impl}}::poll<generator-0>
             at /rustc/4fb7144ed159f94491249e86d5bbd033b5d60550\src\libstd\future.rs:44
  16: std::future::poll_with_tls_context<std::future::GenFuture<generator-0>>
             at /rustc/4fb7144ed159f94491249e86d5bbd033b5d60550\src\libstd\future.rs:102
  17: compressed::gzip_compressed::{{closure}}::{{closure}}
             at .\tests\compressed.rs:120
  18: std::future::{{impl}}::poll<generator-1>
             at /rustc/4fb7144ed159f94491249e86d5bbd033b5d60550\src\libstd\future.rs:44
  19: std::future::poll_with_tls_context<std::future::GenFuture<generator-1>>
             at /rustc/4fb7144ed159f94491249e86d5bbd033b5d60550\src\libstd\future.rs:102
  20: async_std::task::builder::{{impl}}::spawn::{{closure}}<std::future::GenFuture<generator-1>,core::result::Result<(), http_types::error::Error>>
             at C:\Users\Jeremiah\.cargo\registry\src\github.com-1ecc6299db9ec823\async-std-1.5.0\src\task\builder.rs:64
  21: std::future::{{impl}}::poll<generator-0>
             at /rustc/4fb7144ed159f94491249e86d5bbd033b5d60550\src\libstd\future.rs:44
  22: async_task::raw::RawTask<std::future::GenFuture<generator-0>, core::result::Result<(), http_types::error::Error>, closure-1, async_std::task::task::Task>::run<std::future::GenFuture<generator-0>,core::result::Result<(), http_types::error::Error>,closure-1
             at C:\Users\Jeremiah\.cargo\registry\src\github.com-1ecc6299db9ec823\async-task-1.3.1\src\raw.rs:505
  23: async_task::task::Task<async_std::task::task::Task>::run<async_std::task::task::Task>
             at C:\Users\Jeremiah\.cargo\registry\src\github.com-1ecc6299db9ec823\async-task-1.3.1\src\task.rs:239
  24: async_std::task::builder::{{impl}}::run::{{closure}}::{{closure}}
             at C:\Users\Jeremiah\.cargo\registry\src\github.com-1ecc6299db9ec823\async-std-1.5.0\src\task\builder.rs:81
  25: async_std::utils::abort_on_panic<(),closure-0>
             at C:\Users\Jeremiah\.cargo\registry\src\github.com-1ecc6299db9ec823\async-std-1.5.0\src\utils.rs:16
  26: async_std::task::builder::{{impl}}::run::{{closure}}
             at C:\Users\Jeremiah\.cargo\registry\src\github.com-1ecc6299db9ec823\async-std-1.5.0\src\task\builder.rs:81
  27: async_std::task::task::{{impl}}::set_current::{{closure}}<closure-0,()>
             at C:\Users\Jeremiah\.cargo\registry\src\github.com-1ecc6299db9ec823\async-std-1.5.0\src\task\task.rs:129
  28: std::thread::local::LocalKey<core::cell::Cell<const async_std::task::task::Task*>>::try_with<core::cell::Cell<const async_std::task::task::Task*>,closure-0,()>
             at /rustc/4fb7144ed159f94491249e86d5bbd033b5d60550\src\libstd\thread\local.rs:262
  29: std::thread::local::LocalKey<core::cell::Cell<const async_std::task::task::Task*>>::with<core::cell::Cell<const async_std::task::task::Task*>,closure-0,()>
             at /rustc/4fb7144ed159f94491249e86d5bbd033b5d60550\src\libstd\thread\local.rs:239
  30: async_std::task::task::Task::set_current<closure-0,()>
             at C:\Users\Jeremiah\.cargo\registry\src\github.com-1ecc6299db9ec823\async-std-1.5.0\src\task\task.rs:124
  31: async_std::task::builder::Runnable::run
             at C:\Users\Jeremiah\.cargo\registry\src\github.com-1ecc6299db9ec823\async-std-1.5.0\src\task\builder.rs:81
  32: async_std::task::executor::pool::main_loop
             at C:\Users\Jeremiah\.cargo\registry\src\github.com-1ecc6299db9ec823\async-std-1.5.0\src\task\executor\pool.rs:114
  33: core::ops::function::FnOnce::call_once<fn(),()>
             at /rustc/4fb7144ed159f94491249e86d5bbd033b5d60550\src\libcore\ops\function.rs:232
  34: async_std::utils::abort_on_panic<(),fn()>
             at C:\Users\Jeremiah\.cargo\registry\src\github.com-1ecc6299db9ec823\async-std-1.5.0\src\utils.rs:16
  35: async_std::task::executor::pool::POOL::{{closure}}::{{closure}}
             at C:\Users\Jeremiah\.cargo\registry\src\github.com-1ecc6299db9ec823\async-std-1.5.0\src\task\executor\pool.rs:46

@yoshuawuyts
Copy link
Member

I was surprised to discover that Url isn't TryFrom<&str>.

@jbr Waiting for a new version of url to be released: servo/rust-url#569

@jbr
Copy link
Member Author

jbr commented May 21, 2020

@yoshuawuyts Well it's reassuring I'm not the only one surprised by that 😄, and glad to see it's in the works

Copy link
Member

@yoshuawuyts yoshuawuyts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looking really good! -- think we'll have to follow this up with a PR to update our body methods, but that can be done after we merge this

Comment on lines +101 to 114
pub fn set_header(mut self, key: impl Into<HeaderName>, value: impl ToHeaderValues) -> Self {
self.res.insert_header(key, value);
self
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh actually, we should probably remove the Self return type from all of these methods. They should strictly forward to http-types here.

@jbr jbr force-pushed the update-http-types branch from 20c1896 to 92f2ed9 Compare May 22, 2020 23:10
Copy link
Member

@dignifiedquire dignifiedquire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these tests are so much nicer now :)

Copy link
Member

@yoshuawuyts yoshuawuyts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@jbr jbr changed the title update http-types to master http-types and async-h1 2.0.0 May 22, 2020
@yoshuawuyts yoshuawuyts merged commit 204268a into http-rs:master May 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants