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

Create a warpper for application/json content type #664

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions http/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl Response {
pub fn ok<T: Into<String>>(response: T) -> Self {
Response {
code: StatusCode::OK,
content_type: HeaderValue::from_static("application/json; charset=utf-8"),
content_type: application_json(),
content: response.into(),
}
}
Expand All @@ -41,7 +41,7 @@ impl Response {
pub fn service_unavailable<T: Into<String>>(msg: T) -> Self {
Response {
code: StatusCode::SERVICE_UNAVAILABLE,
content_type: HeaderValue::from_static("application/json; charset=utf-8"),
content_type: application_json(),
content: msg.into(),
}
}
Expand Down Expand Up @@ -123,6 +123,10 @@ fn plain_text() -> HeaderValue {
HeaderValue::from_static("text/plain; charset=utf-8")
}

fn application_json() -> HeaderValue {
HeaderValue::from_static("application/json; charset=utf-8")
}

// TODO: Consider switching to a `TryFrom` conversion once it stabilizes.
impl From<Response> for hyper::Response<Body> {
/// Converts from a jsonrpc `Response` to a `hyper::Response`
Expand Down