Using dedicated branch for jsonrpc
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use {multihash, cid, hyper};
|
||||
use {multihash, cid, http};
|
||||
use route::Out;
|
||||
|
||||
pub type Result<T> = ::std::result::Result<T, Error>;
|
||||
@@ -25,7 +25,7 @@ pub enum ServerError {
|
||||
/// Wrapped `std::io::Error`
|
||||
IoError(::std::io::Error),
|
||||
/// Other `hyper` error
|
||||
Other(hyper::error::Error),
|
||||
Other(http::hyper::error::Error),
|
||||
/// Invalid --ipfs-api-interface
|
||||
InvalidInterface
|
||||
}
|
||||
@@ -80,8 +80,8 @@ impl From<::std::io::Error> for ServerError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<hyper::error::Error> for ServerError {
|
||||
fn from(err: hyper::error::Error) -> ServerError {
|
||||
impl From<http::hyper::error::Error> for ServerError {
|
||||
fn from(err: http::hyper::error::Error) -> ServerError {
|
||||
ServerError::Other(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,14 +16,13 @@
|
||||
|
||||
#[macro_use]
|
||||
extern crate mime;
|
||||
extern crate hyper;
|
||||
extern crate multihash;
|
||||
extern crate cid;
|
||||
|
||||
extern crate rlp;
|
||||
extern crate ethcore;
|
||||
extern crate ethcore_util as util;
|
||||
extern crate jsonrpc_http_server;
|
||||
extern crate jsonrpc_http_server as http;
|
||||
|
||||
pub mod error;
|
||||
mod route;
|
||||
@@ -33,13 +32,13 @@ use std::sync::Arc;
|
||||
use std::net::{SocketAddr, IpAddr};
|
||||
use error::ServerError;
|
||||
use route::Out;
|
||||
use hyper::server::{Listening, Handler, Request, Response};
|
||||
use hyper::net::HttpStream;
|
||||
use hyper::header::{self, Vary, ContentLength, ContentType};
|
||||
use hyper::{Next, Encoder, Decoder, Method, RequestUri, StatusCode};
|
||||
use http::hyper::server::{Listening, Handler, Request, Response};
|
||||
use http::hyper::net::HttpStream;
|
||||
use http::hyper::header::{self, Vary, ContentLength, ContentType};
|
||||
use http::hyper::{Next, Encoder, Decoder, Method, RequestUri, StatusCode};
|
||||
use ethcore::client::BlockChainClient;
|
||||
|
||||
pub use jsonrpc_http_server::{AccessControlAllowOrigin, Host, DomainsValidation};
|
||||
pub use http::{AccessControlAllowOrigin, Host, DomainsValidation};
|
||||
|
||||
/// Request/response handler
|
||||
pub struct IpfsHandler {
|
||||
@@ -82,14 +81,14 @@ impl Handler<HttpStream> for IpfsHandler {
|
||||
}
|
||||
|
||||
|
||||
if !jsonrpc_http_server::is_host_allowed(&req, &self.allowed_hosts) {
|
||||
if !http::is_host_allowed(&req, &self.allowed_hosts) {
|
||||
self.out = Out::Bad("Disallowed Host header");
|
||||
|
||||
return Next::write();
|
||||
}
|
||||
|
||||
let cors_header = jsonrpc_http_server::cors_header(&req, &self.cors_domains);
|
||||
if cors_header == jsonrpc_http_server::CorsHeader::Invalid {
|
||||
let cors_header = http::cors_header(&req, &self.cors_domains);
|
||||
if cors_header == http::CorsHeader::Invalid {
|
||||
self.out = Out::Bad("Disallowed Origin header");
|
||||
|
||||
return Next::write();
|
||||
@@ -209,7 +208,7 @@ pub fn start_server(
|
||||
let hosts: DomainsValidation<_> = hosts.map(move |hosts| include_current_interface(hosts, interface, port)).into();
|
||||
|
||||
Ok(
|
||||
hyper::Server::http(&addr)?
|
||||
http::hyper::Server::http(&addr)?
|
||||
.handle(move |_| IpfsHandler::new(cors.clone(), hosts.clone(), client.clone()))
|
||||
.map(|(listening, srv)| {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user