1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-02-22 20:52:27 +00:00

make all fields of response private, we're breaking change anyways

Closes #34
Related to #27
This commit is contained in:
Dominic 2021-01-14 18:45:32 +01:00
parent 44f3c9fe84
commit b7a1193333
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
9 changed files with 23 additions and 21 deletions

View file

@ -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).
## [Unreleased]
### Added
- Support custom HTTP response headers
### Changed
- 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
### Added

View file

@ -7,17 +7,12 @@ use mime::{Mime, APPLICATION_JSON};
/// A response, used to create the final gotham response from.
#[derive(Debug)]
pub struct Response {
#[deprecated(since = "0.1.2", note = "This field will be private in an upcomming release")]
pub status: StatusCode,
#[deprecated(since = "0.1.2", note = "This field will be private in an upcomming release")]
pub body: Body,
#[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
pub(crate) status: StatusCode,
pub(crate) body: Body,
pub(crate) mime: Option<Mime>,
pub(crate) headers: HeaderMap
}
#[allow(deprecated)]
impl Response {
/// Create a new [Response] from raw data.
#[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].
pub fn add_header(&mut self, name: HeaderName, value: HeaderValue) {
pub fn header(&mut self, name: HeaderName, value: HeaderValue) {
self.headers.insert(name, value);
}

View file

@ -99,7 +99,6 @@ fn errorlog<E: Display>(e: E) {
#[cfg(not(feature = "errorlog"))]
fn errorlog<E>(_e: E) {}
#[allow(deprecated)]
fn handle_error<E>(e: E) -> Pin<Box<dyn Future<Output = Result<Response, E::Err>> + Send>>
where
E: Display + IntoResponseError
@ -161,7 +160,6 @@ mod test {
struct MsgError;
#[test]
#[allow(deprecated)]
fn result_from_future() {
let nc = NoContent::default();
let res = block_on(nc.into_response()).unwrap();

View file

@ -92,7 +92,6 @@ where
}
#[cfg(test)]
#[allow(deprecated)]
mod test {
use super::*;
use futures_executor::block_on;

View file

@ -131,7 +131,6 @@ mod test {
use mime::TEXT_PLAIN;
#[test]
#[allow(deprecated)]
fn raw_response() {
let msg = "Test";
let raw = Raw::new(msg, TEXT_PLAIN);

View file

@ -49,7 +49,6 @@ where
}
#[cfg(test)]
#[allow(deprecated)]
mod test {
use super::*;
use crate::result::OrAllTypes;

View file

@ -124,7 +124,6 @@ mod test {
}
#[test]
#[allow(deprecated)]
fn success_always_successfull() {
let success: Success<Msg> = Msg::default().into();
let res = block_on(success.into_response()).expect("didn't expect error response");

View file

@ -81,7 +81,6 @@ pub trait DrawResourceRoutes {
fn remove<Handler: ResourceRemove>(&mut self);
}
#[allow(deprecated)]
fn response_from(res: Response, state: &State) -> gotham::hyper::Response<Body> {
let mut r = create_empty_response(state, res.status);
let headers = r.headers_mut();

View file

@ -21,8 +21,8 @@ mod resource_error {
fn io_error() {
let err = Error::IoError(std::io::Error::last_os_error());
let res = err.into_response_error().unwrap();
assert_eq!(res.status, StatusCode::INTERNAL_SERVER_ERROR);
assert_eq!(res.mime, Some(APPLICATION_JSON));
assert_eq!(res.status(), StatusCode::INTERNAL_SERVER_ERROR);
assert_eq!(res.mime(), Some(&APPLICATION_JSON));
}
#[test]
@ -31,7 +31,7 @@ mod resource_error {
assert_eq!(&format!("{}", err), "Internal Server Error: Brocken");
let res = err.into_response_error().unwrap();
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.status(), StatusCode::INTERNAL_SERVER_ERROR);
assert_eq!(res.mime(), None); // TODO shouldn't this be a json error message?
}
}