mirror of
https://gitlab.com/msrd0/gotham-restful.git
synced 2025-02-23 04:52:28 +00:00
make all fields of response private, we're breaking change anyways
Closes #34 Related to #27
This commit is contained in:
parent
44f3c9fe84
commit
b7a1193333
9 changed files with 23 additions and 21 deletions
|
@ -5,8 +5,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
### Added
|
||||||
|
- Support custom HTTP response headers
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- The cors handler can now copy headers from the request if desired
|
- The cors handler can now copy headers from the request if desired
|
||||||
|
- All fields of `Response` are now private
|
||||||
|
|
||||||
## [0.1.1] - 2020-12-28
|
## [0.1.1] - 2020-12-28
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -7,17 +7,12 @@ use mime::{Mime, APPLICATION_JSON};
|
||||||
/// A response, used to create the final gotham response from.
|
/// A response, used to create the final gotham response from.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Response {
|
pub struct Response {
|
||||||
#[deprecated(since = "0.1.2", note = "This field will be private in an upcomming release")]
|
pub(crate) status: StatusCode,
|
||||||
pub status: StatusCode,
|
pub(crate) body: Body,
|
||||||
#[deprecated(since = "0.1.2", note = "This field will be private in an upcomming release")]
|
pub(crate) mime: Option<Mime>,
|
||||||
pub body: Body,
|
pub(crate) headers: HeaderMap
|
||||||
#[deprecated(since = "0.1.2", note = "This field will be private in an upcomming release")]
|
|
||||||
pub mime: Option<Mime>,
|
|
||||||
#[deprecated(since = "0.1.2", note = "This field will be private in an upcomming release")]
|
|
||||||
pub headers: HeaderMap
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(deprecated)]
|
|
||||||
impl Response {
|
impl Response {
|
||||||
/// Create a new [Response] from raw data.
|
/// Create a new [Response] from raw data.
|
||||||
#[must_use = "Creating a response is pointless if you don't use it"]
|
#[must_use = "Creating a response is pointless if you don't use it"]
|
||||||
|
@ -63,8 +58,18 @@ impl Response {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return the status code of this [Response].
|
||||||
|
pub fn status(&self) -> StatusCode {
|
||||||
|
self.status
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return the mime type of this [Response].
|
||||||
|
pub fn mime(&self) -> Option<&Mime> {
|
||||||
|
self.mime.as_ref()
|
||||||
|
}
|
||||||
|
|
||||||
/// Add an HTTP header to the [Response].
|
/// Add an HTTP header to the [Response].
|
||||||
pub fn add_header(&mut self, name: HeaderName, value: HeaderValue) {
|
pub fn header(&mut self, name: HeaderName, value: HeaderValue) {
|
||||||
self.headers.insert(name, value);
|
self.headers.insert(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,7 +99,6 @@ fn errorlog<E: Display>(e: E) {
|
||||||
#[cfg(not(feature = "errorlog"))]
|
#[cfg(not(feature = "errorlog"))]
|
||||||
fn errorlog<E>(_e: E) {}
|
fn errorlog<E>(_e: E) {}
|
||||||
|
|
||||||
#[allow(deprecated)]
|
|
||||||
fn handle_error<E>(e: E) -> Pin<Box<dyn Future<Output = Result<Response, E::Err>> + Send>>
|
fn handle_error<E>(e: E) -> Pin<Box<dyn Future<Output = Result<Response, E::Err>> + Send>>
|
||||||
where
|
where
|
||||||
E: Display + IntoResponseError
|
E: Display + IntoResponseError
|
||||||
|
@ -161,7 +160,6 @@ mod test {
|
||||||
struct MsgError;
|
struct MsgError;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[allow(deprecated)]
|
|
||||||
fn result_from_future() {
|
fn result_from_future() {
|
||||||
let nc = NoContent::default();
|
let nc = NoContent::default();
|
||||||
let res = block_on(nc.into_response()).unwrap();
|
let res = block_on(nc.into_response()).unwrap();
|
||||||
|
|
|
@ -92,7 +92,6 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[allow(deprecated)]
|
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use futures_executor::block_on;
|
use futures_executor::block_on;
|
||||||
|
|
|
@ -131,7 +131,6 @@ mod test {
|
||||||
use mime::TEXT_PLAIN;
|
use mime::TEXT_PLAIN;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[allow(deprecated)]
|
|
||||||
fn raw_response() {
|
fn raw_response() {
|
||||||
let msg = "Test";
|
let msg = "Test";
|
||||||
let raw = Raw::new(msg, TEXT_PLAIN);
|
let raw = Raw::new(msg, TEXT_PLAIN);
|
||||||
|
|
|
@ -49,7 +49,6 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[allow(deprecated)]
|
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::result::OrAllTypes;
|
use crate::result::OrAllTypes;
|
||||||
|
|
|
@ -124,7 +124,6 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[allow(deprecated)]
|
|
||||||
fn success_always_successfull() {
|
fn success_always_successfull() {
|
||||||
let success: Success<Msg> = Msg::default().into();
|
let success: Success<Msg> = Msg::default().into();
|
||||||
let res = block_on(success.into_response()).expect("didn't expect error response");
|
let res = block_on(success.into_response()).expect("didn't expect error response");
|
||||||
|
|
|
@ -81,7 +81,6 @@ pub trait DrawResourceRoutes {
|
||||||
fn remove<Handler: ResourceRemove>(&mut self);
|
fn remove<Handler: ResourceRemove>(&mut self);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(deprecated)]
|
|
||||||
fn response_from(res: Response, state: &State) -> gotham::hyper::Response<Body> {
|
fn response_from(res: Response, state: &State) -> gotham::hyper::Response<Body> {
|
||||||
let mut r = create_empty_response(state, res.status);
|
let mut r = create_empty_response(state, res.status);
|
||||||
let headers = r.headers_mut();
|
let headers = r.headers_mut();
|
||||||
|
|
|
@ -21,8 +21,8 @@ mod resource_error {
|
||||||
fn io_error() {
|
fn io_error() {
|
||||||
let err = Error::IoError(std::io::Error::last_os_error());
|
let err = Error::IoError(std::io::Error::last_os_error());
|
||||||
let res = err.into_response_error().unwrap();
|
let res = err.into_response_error().unwrap();
|
||||||
assert_eq!(res.status, StatusCode::INTERNAL_SERVER_ERROR);
|
assert_eq!(res.status(), StatusCode::INTERNAL_SERVER_ERROR);
|
||||||
assert_eq!(res.mime, Some(APPLICATION_JSON));
|
assert_eq!(res.mime(), Some(&APPLICATION_JSON));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -31,7 +31,7 @@ mod resource_error {
|
||||||
assert_eq!(&format!("{}", err), "Internal Server Error: Brocken");
|
assert_eq!(&format!("{}", err), "Internal Server Error: Brocken");
|
||||||
|
|
||||||
let res = err.into_response_error().unwrap();
|
let res = err.into_response_error().unwrap();
|
||||||
assert_eq!(res.status, StatusCode::INTERNAL_SERVER_ERROR);
|
assert_eq!(res.status(), StatusCode::INTERNAL_SERVER_ERROR);
|
||||||
assert_eq!(res.mime, None); // TODO shouldn't this be a json error message?
|
assert_eq!(res.mime(), None); // TODO shouldn't this be a json error message?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue