Skip to content

Commit

Permalink
add Cache-Control: private hdr to non-static stuff
Browse files Browse the repository at this point in the history
for #26
  • Loading branch information
scottlamb committed Dec 2, 2018
1 parent 4f87c16 commit 3f76096
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,14 +775,20 @@ impl ::hyper::service::Service for Service {
type Future = Box<Future<Item = Response<Self::ResBody>, Error = Self::Error> + Send + 'static>;

fn call(&mut self, req: Request<::hyper::Body>) -> Self::Future {
fn wrap<R: Future<Item = Response<Body>, Error = Response<Body>> + Send + 'static>(r: R)
-> Box<Future<Item = Response<Body>, Error = BoxedError> + Send + 'static> {
return Box::new(r.or_else(|e| Ok(e)))
fn wrap<R>(is_private: bool, r: R)
-> Box<Future<Item = Response<Body>, Error = BoxedError> + Send + 'static>
where R: Future<Item = Response<Body>, Error = Response<Body>> + Send + 'static {
return Box::new(r.or_else(|e| Ok(e)).map(move |mut r| {
if is_private {
r.headers_mut().insert("Cache-Control", HeaderValue::from_static("private"));
}
r
}))
}

fn wrap_r(r: ResponseResult)
fn wrap_r(is_private: bool, r: ResponseResult)
-> Box<Future<Item = Response<Body>, Error = BoxedError> + Send + 'static> {
return wrap(future::result(r))
return wrap(is_private, future::result(r))
}

let p = decode_path(req.uri().path());
Expand All @@ -799,30 +805,30 @@ impl ::hyper::service::Service for Service {
return Box::new(future::ok(
plain_response(StatusCode::UNAUTHORIZED, "unauthorized")));
}
match decode_path(req.uri().path()) {
Path::InitSegment(sha1) => wrap_r(self.0.init_segment(sha1, &req)),
Path::TopLevel => wrap_r(self.0.top_level(&req, session)),
Path::Request => wrap_r(self.0.request(&req)),
Path::Camera(uuid) => wrap_r(self.0.camera(&req, uuid)),
match p {
Path::InitSegment(sha1) => wrap_r(true, self.0.init_segment(sha1, &req)),
Path::TopLevel => wrap_r(true, self.0.top_level(&req, session)),
Path::Request => wrap_r(true, self.0.request(&req)),
Path::Camera(uuid) => wrap_r(true, self.0.camera(&req, uuid)),
Path::StreamRecordings(uuid, type_) => {
wrap_r(self.0.stream_recordings(&req, uuid, type_))
wrap_r(true, self.0.stream_recordings(&req, uuid, type_))
},
Path::StreamViewMp4(uuid, type_) => {
wrap_r(self.0.stream_view_mp4(&req, uuid, type_, mp4::Type::Normal))
wrap_r(true, self.0.stream_view_mp4(&req, uuid, type_, mp4::Type::Normal))
},
Path::StreamViewMp4Segment(uuid, type_) => {
wrap_r(self.0.stream_view_mp4(&req, uuid, type_, mp4::Type::MediaSegment))
wrap_r(true, self.0.stream_view_mp4(&req, uuid, type_, mp4::Type::MediaSegment))
},
Path::NotFound => wrap(future::err(not_found("path not understood"))),
Path::Login => wrap(self.with_form_body(req).and_then({
Path::NotFound => wrap(true, future::err(not_found("path not understood"))),
Path::Login => wrap(true, self.with_form_body(req).and_then({
let s = self.clone();
move |(req, b)| { s.0.login(&req, b) }
})),
Path::Logout => wrap(self.with_form_body(req).and_then({
Path::Logout => wrap(true, self.with_form_body(req).and_then({
let s = self.clone();
move |(req, b)| { s.0.logout(&req, b) }
})),
Path::Static => wrap_r(self.0.static_file(&req, req.uri().path())),
Path::Static => wrap_r(false, self.0.static_file(&req, req.uri().path())),
}
}
}
Expand Down

0 comments on commit 3f76096

Please sign in to comment.