-
Notifications
You must be signed in to change notification settings - Fork 274
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
Conversation
afd2f8d
to
68c1faa
Compare
There was a problem hiding this 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.
http/src/handler.rs
Outdated
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()); |
There was a problem hiding this comment.
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
http/src/handler.rs
Outdated
Ascii::new("content-type".to_owned()), | ||
Ascii::new("accept".to_owned()), | ||
])); | ||
headers.append(header::ACCESS_CONTROL_ALLOW_METHODS, Method::OPTIONS.as_str().parse().unwrap()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
http/src/handler.rs
Outdated
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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unwrap
-> expect
server-utils/src/stream_codec.rs
Outdated
@@ -1,5 +1,6 @@ | |||
use std::{io, str}; | |||
use tokio_io::codec::{Decoder, Encoder}; | |||
// use tokio_io::codec::{Decoder, Encoder}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stray comment
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" } |
There was a problem hiding this comment.
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.
e933137
to
9f50f79
Compare
Everything except deciding what to do about the |
25ca8c2
to
615e04a
Compare
* 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
615e04a
to
82b3686
Compare
82b3686
to
5341632
Compare
* 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
5341632
to
29a194e
Compare
There was a problem hiding this 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
http/src/handler.rs
Outdated
@@ -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() { |
There was a problem hiding this comment.
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.
http/examples/http_meta.rs
Outdated
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()); |
There was a problem hiding this comment.
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.
http/src/handler.rs
Outdated
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")); |
There was a problem hiding this comment.
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
http/src/handler.rs
Outdated
|
||
/// Returns true if the `content_type` header indicates a valid JSON | ||
/// message. | ||
fn is_json(content_type: Option<&header::HeaderValue>) -> bool { | ||
match content_type { |
There was a problem hiding this comment.
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>; |
There was a problem hiding this comment.
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.
core/src/calls.rs
Outdated
@@ -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 {} |
There was a problem hiding this comment.
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
http/src/tests.rs
Outdated
@@ -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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove please
http/src/tests.rs
Outdated
@@ -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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove please
ipc/src/server.rs
Outdated
) | ||
).split(); | ||
let (writer, reader) = Framed::new( | ||
io_stream, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird indentation
Address grumbles and refactor cors headers
Just completely out of curiosity, I'm sure there's a good reason, why handle headers as ascii instead of |
* 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`.
* 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`.
* 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`.
* 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`.
* 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`.
* 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`.
* 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`.
Replace
tokio_core
withtokio
.server_utils::reactor::Remote
has been renamed toExecutor
.The
Shared
variant now contains atokio::runtime::TaskExecutor
.This may need to be changed to a trait object (of
tokio::executor::Executor
) or be otherwise abstracted to conceal thetype 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