Add cache-control header to HTTP responses based on mime #41

Manually merged
dessalines merged 1 commits from cache-control into master 2020-06-02 18:04:10 +00:00
Owner

Got this deployed on https://test.lemmy.ml/.

Here is an analyis, note the result for "Leverage browser caching" https://gtmetrix.com/compare/IvgJgdKn/av79Z7K6

Some notes:

  • I'm not sure what value we should set for the cache-control header, any suggestions?
  • the wrapper should be a seperate function but its really complicated with the weird types
  • the unwrap() should be removed, but ? doesnt work (again, weird types)
Got this deployed on https://test.lemmy.ml/. Here is an analyis, note the result for "Leverage browser caching" https://gtmetrix.com/compare/IvgJgdKn/av79Z7K6 Some notes: - I'm not sure what value we should set for the cache-control header, any suggestions? - the wrapper should be a seperate function but its really complicated with the weird types - the unwrap() should be removed, but `?` doesnt work (again, weird types)
dessalines reviewed 2020-05-31 14:50:48 +00:00
@ -54,0 +67,4 @@
}
Ok(res)
}
})
Owner

This seems kinda messy, the only cached resources need to be the static files: https://actix.rs/docs/static-files/

There should be a way to add the cache-control header to them directly, as well as the etags / last-modified.

This seems kinda messy, the only cached resources need to be the static files: https://actix.rs/docs/static-files/ There should be a way to add the cache-control header to them directly, as well as the etags / last-modified.
Author
Owner

Unfortunately I couldnt find any other way. Only thing I found would apply the headers to all requests. etag/last-modified are already set by default.

Unfortunately I couldnt find any other way. Only thing I found would apply the headers to all requests. etag/last-modified are already set by default.
Owner

I'm asking the actix-web ppl in their gitter channel right now. Also is there any reason we couldn't do this through our nginx template,

I'm asking the actix-web ppl in their gitter channel right now. Also is there any reason we couldn't do this through our nginx template,
Owner

I think maybe it didn't work but I don't remember.

I think maybe it didn't work but I don't remember.
Author
Owner

Nginx should work, but I think its cleaner to handle this directly in Lemmy, in case people use a different reverse proxy. Or in case we want to change it in the future.

Nginx should work, but I think its cleaner to handle this directly in Lemmy, in case people use a different reverse proxy. Or in case we want to change it in the future.
Author
Owner

I'm trying to clean this up by moving the lambda into a seperate function, but it always ends with the error expected bound lifetime parameter, found concrete lifetime, no idea how to fix that.

I pushed that version in case you want to have a look at it.

I'm trying to clean this up by moving the lambda into a seperate function, but it always ends with the error `expected bound lifetime parameter, found concrete lifetime`, no idea how to fix that. I pushed that version in case you want to have a look at it.
Author
Owner
Asked on the Rust forum about this: https://users.rust-lang.org/t/how-to-fix-expected-bound-lifetime-parameter-found-concrete-lifetime/43677
Author
Owner

Okay got it working thanks to a comment on the Rust forum!

Now the only question is what's a good value for max-age.

Okay got it working thanks to a comment on the Rust forum! Now the only question is what's a good value for max-age.
Owner

1 year is probably fine, I'll test this out now locally too.

1 year is probably fine, I'll test this out now locally too.
dessalines closed this pull request 2020-06-02 18:04:10 +00:00
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: LemmyNet/lemmy#41
No description provided.