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

OPTIONS request 'Content-type' should not be json #58

Merged
merged 2 commits into from Mar 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 8 additions & 8 deletions minihttp/src/lib.rs
Expand Up @@ -308,14 +308,6 @@ impl<M: jsonrpc::Metadata, S: jsonrpc::Middleware<M>> tokio_service::Service for
).boxed();
}

// Validate content type
let content_type = request.header("Content-type");
if !is_json(content_type) {
return future::ok(
res::invalid_content_type()
).boxed();
}

// Extract CORS headers
let origin = request.header("Origin");
let cors = cors::get_cors_header(origin, &self.cors_domains);
Expand All @@ -327,6 +319,14 @@ impl<M: jsonrpc::Metadata, S: jsonrpc::Middleware<M>> tokio_service::Service for
).boxed();
}

// Validate content type
let content_type = request.header("Content-type");
if !is_json(content_type) {
return future::ok(
res::invalid_content_type()
).boxed();
}

// Extract metadata
let metadata = self.meta_extractor.read_metadata(&request);

Expand Down
16 changes: 16 additions & 0 deletions minihttp/src/tests.rs
Expand Up @@ -87,6 +87,22 @@ fn should_return_method_not_allowed_for_get() {
assert_eq!(response.body, "Used HTTP Method is not allowed. POST or OPTIONS is required.\n".to_owned());
}

#[test]
fn should_ignore_media_type_if_options() {
// given
let server = serve();

// when
let response = request(server,
Method::Options,
Headers::new(),
"{}",
);

// then
assert_eq!(response.status, StatusCode::Ok);
}

#[test]
fn should_return_unsupported_media_type_if_not_json() {
// given
Expand Down