Skip to content
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

Update hyper to version 0.12. #303

Merged
merged 8 commits into from
Sep 27, 2018
Merged

Conversation

c0gent
Copy link
Contributor

@c0gent c0gent commented Aug 27, 2018

  • Replace tokio_core with tokio.

  • server_utils::reactor::Remote has been renamed to Executor.
    The Shared variant now contains a tokio::runtime::TaskExecutor.
    This may need to be changed to a trait object (of
    tokio::executor::Executor) or be otherwise abstracted to conceal the
    type in the public API.

  • Bump crate versions to 0.9

Eventually, I'll be updating Parity to use these new changes and to remove tokio_core etc. You may want to consider holding off on merging until I'm done, to ensure everything works properly. I don't have an estimate on when that will be.

Closes #298

Copy link
Contributor

@tomusdrw tomusdrw 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! Couple of fixes required before the merge though.

header::qitem(mime::APPLICATION_JSON)
]));
headers.append(header::ALLOW, Method::OPTIONS.as_str().parse().unwrap());
headers.append(header::ALLOW, Method::POST.as_str().parse().unwrap());
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use HeaderValue::from_static here or turn unwraps into expects

Ascii::new("content-type".to_owned()),
Ascii::new("accept".to_owned()),
]));
headers.append(header::ACCESS_CONTROL_ALLOW_METHODS, Method::OPTIONS.as_str().parse().unwrap());
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

if let Some(cors_max_age) = cors_max_age {
headers.set(header::AccessControlMaxAge(cors_max_age));
headers.append(header::ACCESS_CONTROL_MAX_AGE, HeaderValue::from_str(&cors_max_age.to_string()).unwrap());
Copy link
Contributor

Choose a reason for hiding this comment

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

unwrap -> expect

http/src/lib.rs Show resolved Hide resolved
http/src/lib.rs Show resolved Hide resolved
@@ -1,5 +1,6 @@
use std::{io, str};
use tokio_io::codec::{Decoder, Encoder};
// use tokio_io::codec::{Decoder, Encoder};
Copy link
Contributor

Choose a reason for hiding this comment

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

stray comment

tcp/src/server.rs Show resolved Hide resolved
http/src/response.rs Outdated Show resolved Hide resolved
ipc/Cargo.toml Outdated
parity-tokio-ipc = { git = "https://github.com/nikvolf/parity-tokio-ipc", branch = "stable" }
jsonrpc-core = { version = "9.0", path = "../core" }
jsonrpc-server-utils = { version = "9.0", path = "../server-utils" }
parity-tokio-ipc = { git = "https://github.com/poanetwork/parity-tokio-ipc" }
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to switch to mainstream libs before merging.

server-utils/src/reactor.rs Show resolved Hide resolved
@c0gent c0gent force-pushed the c0gent-hyper branch 2 times, most recently from e933137 to 9f50f79 Compare August 28, 2018 22:17
@c0gent
Copy link
Contributor Author

c0gent commented Aug 28, 2018

Everything except deciding what to do about the Response conversion is done.

@c0gent c0gent force-pushed the c0gent-hyper branch 4 times, most recently from 25ca8c2 to 615e04a Compare September 14, 2018 23:04
* Replace `tokio_core` with `tokio`.

* `server_utils::reactor::Remote` has been renamed to `Executor`.
  The `Shared` variant now contains a `tokio::runtime::TaskExecutor`.
  This may need to be changed to a trait object (of
  `tokio::executor::Executor`) or be otherwise abstracted to conceal the
  type in the public API.

* Bump crate versions to 0.9
* Replace `tokio_core` with `tokio`.

* `server_utils::reactor::Remote` has been renamed to `Executor`.
  The `Shared` variant now contains a `tokio::runtime::TaskExecutor`.
  This may need to be changed to a trait object (of
  `tokio::executor::Executor`) or be otherwise abstracted to conceal the
  type in the public API.

* Bump crate versions to 0.9
Copy link
Contributor

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

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

Grumbles self addressed: c0gent#1

@@ -317,34 +316,34 @@ impl<M: Metadata, S: Middleware<M>> RpcHandler<M, S> {
let metadata = self.jsonrpc_handler.extractor.read_metadata(&request);

// Proceed
match *request.method() {
match request.method().clone() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need to clone here? *request.method() should work fine.

let auth = auth.map(|h| h.token.clone());
.meta_extractor(|req: &hyper::Request<hyper::Body>| {
let auth = req.headers().get(hyper::header::AUTHORIZATION)
.map(|h| h.to_str().expect("Invalid authorization value").to_owned());
Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO better to use some default value in case of error here, I know it's only an example, but this produces a server that panics on invalid payload which is not really something that we should recommend.

headers.append(header::ACCESS_CONTROL_ALLOW_METHODS, Method::POST.as_str().parse()
.expect("`Method` will always parse; qed"));

headers.append(header::ACCESS_CONTROL_ALLOW_HEADERS, HeaderValue::from_static("origin"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Will require a merge with #305


/// Returns true if the `content_type` header indicates a valid JSON
/// message.
fn is_json(content_type: Option<&header::HeaderValue>) -> bool {
match content_type {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be simplfiied:

match content_type.and_then(|val| val.to_str().ok()) {
  Some("application/json") => true,
  Some("application/json; charset=utf-8") => true,
  None => false
}

core/src/io.rs Outdated
@@ -11,7 +11,7 @@ use types::{Error, ErrorCode, Version};
use types::{Request, Response, Call, Output};

/// A type representing middleware or RPC response before serialization.
pub type FutureResponse = Box<Future<Item=Option<Response>, Error=()> + Send>;
pub type FutureResponse = Box<Future<Item=Option<Response>, Error=()> + Send + 'static>;
Copy link
Contributor

Choose a reason for hiding this comment

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

'static is implicit from Box we don't need it here.

@@ -5,7 +5,7 @@ use futures::{Future, IntoFuture};
use BoxFuture;

/// Metadata trait
pub trait Metadata: Clone + Send + 'static {}
pub trait Metadata: Clone + Send + Sync + 'static {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does Metadata have to be Sync? We should never really access it inside the server, so Send should be enough

@@ -159,7 +159,8 @@ fn should_handle_health_endpoint_failure() {

// then
assert_eq!(response.status, "HTTP/1.1 503 Service Unavailable".to_owned());
assert_eq!(response.body, "25\n{\"code\":-34,\"message\":\"Server error\"}\n0\n");
// assert_eq!(response.body, "25\n{\"code\":-34,\"message\":\"Server error\"}\n0\n");
Copy link
Contributor

Choose a reason for hiding this comment

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

remove please

@@ -458,7 +460,8 @@ fn should_add_cors_header_for_null_origin_when_all() {
// then
assert_eq!(response.status, "HTTP/1.1 200 OK".to_owned());
assert_eq!(response.body, method_not_found());
assert!(response.headers.contains("Access-Control-Allow-Origin: null"), "Headers missing in {}", response.headers);
// println!("HEADERS: {:?}", response.headers);
Copy link
Contributor

Choose a reason for hiding this comment

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

remove please

)
).split();
let (writer, reader) = Framed::new(
io_stream,
Copy link
Contributor

Choose a reason for hiding this comment

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

Weird indentation

@c0gent
Copy link
Contributor Author

c0gent commented Sep 27, 2018

Just completely out of curiosity, I'm sure there's a good reason, why handle headers as ascii instead of HeaderName/HeaderValue in server-utils/src/cors.rs?

@tomusdrw
Copy link
Contributor

@c0gent I'd like to keep server-utils agnostic to the framework we are using in http server (some stuff is shared with ws and minihttp servers) - so I don't really want to pull hyper into that dep. I missed that hyper got included in #305 so piggybacking this change on your PR :)

@tomusdrw tomusdrw merged commit 9e06214 into paritytech:master Sep 27, 2018
CriesofCarrots pushed a commit to CriesofCarrots/jsonrpc that referenced this pull request Sep 28, 2018
* Update hyper to version 0.12.

* Replace `tokio_core` with `tokio`.

* `server_utils::reactor::Remote` has been renamed to `Executor`.
  The `Shared` variant now contains a `tokio::runtime::TaskExecutor`.
  This may need to be changed to a trait object (of
  `tokio::executor::Executor`) or be otherwise abstracted to conceal the
  type in the public API.

* Bump crate versions to 0.9

* Update hyper to version 0.12.

* Replace `tokio_core` with `tokio`.

* `server_utils::reactor::Remote` has been renamed to `Executor`.
  The `Shared` variant now contains a `tokio::runtime::TaskExecutor`.
  This may need to be changed to a trait object (of
  `tokio::executor::Executor`) or be otherwise abstracted to conceal the
  type in the public API.

* Bump crate versions to 0.9

* Fix compilation of hyper-0.2

* Address grumbles.

* Re-export `AllowCors` from `http`.
CriesofCarrots pushed a commit to CriesofCarrots/jsonrpc that referenced this pull request Sep 28, 2018
* Update hyper to version 0.12.

* Replace `tokio_core` with `tokio`.

* `server_utils::reactor::Remote` has been renamed to `Executor`.
  The `Shared` variant now contains a `tokio::runtime::TaskExecutor`.
  This may need to be changed to a trait object (of
  `tokio::executor::Executor`) or be otherwise abstracted to conceal the
  type in the public API.

* Bump crate versions to 0.9

* Update hyper to version 0.12.

* Replace `tokio_core` with `tokio`.

* `server_utils::reactor::Remote` has been renamed to `Executor`.
  The `Shared` variant now contains a `tokio::runtime::TaskExecutor`.
  This may need to be changed to a trait object (of
  `tokio::executor::Executor`) or be otherwise abstracted to conceal the
  type in the public API.

* Bump crate versions to 0.9

* Fix compilation of hyper-0.2

* Address grumbles.

* Re-export `AllowCors` from `http`.
CriesofCarrots pushed a commit to CriesofCarrots/jsonrpc that referenced this pull request Sep 28, 2018
* Update hyper to version 0.12.

* Replace `tokio_core` with `tokio`.

* `server_utils::reactor::Remote` has been renamed to `Executor`.
  The `Shared` variant now contains a `tokio::runtime::TaskExecutor`.
  This may need to be changed to a trait object (of
  `tokio::executor::Executor`) or be otherwise abstracted to conceal the
  type in the public API.

* Bump crate versions to 0.9

* Update hyper to version 0.12.

* Replace `tokio_core` with `tokio`.

* `server_utils::reactor::Remote` has been renamed to `Executor`.
  The `Shared` variant now contains a `tokio::runtime::TaskExecutor`.
  This may need to be changed to a trait object (of
  `tokio::executor::Executor`) or be otherwise abstracted to conceal the
  type in the public API.

* Bump crate versions to 0.9

* Fix compilation of hyper-0.2

* Address grumbles.

* Re-export `AllowCors` from `http`.
CriesofCarrots pushed a commit to CriesofCarrots/jsonrpc that referenced this pull request Sep 28, 2018
* Update hyper to version 0.12.

* Replace `tokio_core` with `tokio`.

* `server_utils::reactor::Remote` has been renamed to `Executor`.
  The `Shared` variant now contains a `tokio::runtime::TaskExecutor`.
  This may need to be changed to a trait object (of
  `tokio::executor::Executor`) or be otherwise abstracted to conceal the
  type in the public API.

* Bump crate versions to 0.9

* Update hyper to version 0.12.

* Replace `tokio_core` with `tokio`.

* `server_utils::reactor::Remote` has been renamed to `Executor`.
  The `Shared` variant now contains a `tokio::runtime::TaskExecutor`.
  This may need to be changed to a trait object (of
  `tokio::executor::Executor`) or be otherwise abstracted to conceal the
  type in the public API.

* Bump crate versions to 0.9

* Fix compilation of hyper-0.2

* Address grumbles.

* Re-export `AllowCors` from `http`.
CriesofCarrots pushed a commit to CriesofCarrots/jsonrpc that referenced this pull request Sep 28, 2018
* Update hyper to version 0.12.

* Replace `tokio_core` with `tokio`.

* `server_utils::reactor::Remote` has been renamed to `Executor`.
  The `Shared` variant now contains a `tokio::runtime::TaskExecutor`.
  This may need to be changed to a trait object (of
  `tokio::executor::Executor`) or be otherwise abstracted to conceal the
  type in the public API.

* Bump crate versions to 0.9

* Update hyper to version 0.12.

* Replace `tokio_core` with `tokio`.

* `server_utils::reactor::Remote` has been renamed to `Executor`.
  The `Shared` variant now contains a `tokio::runtime::TaskExecutor`.
  This may need to be changed to a trait object (of
  `tokio::executor::Executor`) or be otherwise abstracted to conceal the
  type in the public API.

* Bump crate versions to 0.9

* Fix compilation of hyper-0.2

* Address grumbles.

* Re-export `AllowCors` from `http`.
CriesofCarrots pushed a commit to solana-labs/jsonrpc that referenced this pull request Sep 28, 2018
* Update hyper to version 0.12.

* Replace `tokio_core` with `tokio`.

* `server_utils::reactor::Remote` has been renamed to `Executor`.
  The `Shared` variant now contains a `tokio::runtime::TaskExecutor`.
  This may need to be changed to a trait object (of
  `tokio::executor::Executor`) or be otherwise abstracted to conceal the
  type in the public API.

* Bump crate versions to 0.9

* Update hyper to version 0.12.

* Replace `tokio_core` with `tokio`.

* `server_utils::reactor::Remote` has been renamed to `Executor`.
  The `Shared` variant now contains a `tokio::runtime::TaskExecutor`.
  This may need to be changed to a trait object (of
  `tokio::executor::Executor`) or be otherwise abstracted to conceal the
  type in the public API.

* Bump crate versions to 0.9

* Fix compilation of hyper-0.2

* Address grumbles.

* Re-export `AllowCors` from `http`.
CriesofCarrots pushed a commit to solana-labs/jsonrpc that referenced this pull request Sep 28, 2018
* Update hyper to version 0.12.

* Replace `tokio_core` with `tokio`.

* `server_utils::reactor::Remote` has been renamed to `Executor`.
  The `Shared` variant now contains a `tokio::runtime::TaskExecutor`.
  This may need to be changed to a trait object (of
  `tokio::executor::Executor`) or be otherwise abstracted to conceal the
  type in the public API.

* Bump crate versions to 0.9

* Update hyper to version 0.12.

* Replace `tokio_core` with `tokio`.

* `server_utils::reactor::Remote` has been renamed to `Executor`.
  The `Shared` variant now contains a `tokio::runtime::TaskExecutor`.
  This may need to be changed to a trait object (of
  `tokio::executor::Executor`) or be otherwise abstracted to conceal the
  type in the public API.

* Bump crate versions to 0.9

* Fix compilation of hyper-0.2

* Address grumbles.

* Re-export `AllowCors` from `http`.
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.

2 participants