Skip to content

Commit

Permalink
Add Cors for setting CORS headers (#112)
Browse files Browse the repository at this point in the history
* Add `Cors` for settings CORS headers

* Pass layer along so config isn't lost

* Support allowing origin via closure

* Check for `Access-Control-Request-Method`

* Use `None` as default for `Max-Age`

* Add example for allowing multiple headers

* Fix wrong method check

* Also check for any

* Restrictive config by default, with "permissive" helper

* Change status for prelight response

* Make setting origin with predicate more consistent

* Merge clauses

* Use `WILDCARD` constant

* typo

* Conditionally set `allow-credentials`

* Add note to `Access-Control-Allow-Headers`

* minor docs tweaks

* Make `Any` constructor private and expose `any()` function
  • Loading branch information
davidpdrsn committed Nov 13, 2021
1 parent 0e5e83b commit c785742
Show file tree
Hide file tree
Showing 4 changed files with 828 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tower-http/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

# Unreleased

- New middleware: Add `Cors` for setting [CORS] headers ([#112])
- New middleware: Add `AsyncRequireAuthorization` ([#118])
- `Compression`: Don't recompress HTTP responses ([#140])
- `Compression` and `Decompression`: Pass configuration from layer into middleware ([#132])
Expand All @@ -17,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `ServeDir`: Return `404 Not Found` on requests to directories if
`append_index_html_on_directories` is set to `false` ([#122])

[#112]: https://github.com/tower-rs/tower-http/pull/112
[#118]: https://github.com/tower-rs/tower-http/pull/118
[#140]: https://github.com/tower-rs/tower-http/pull/140
[#132]: https://github.com/tower-rs/tower-http/pull/132
Expand Down Expand Up @@ -52,3 +54,5 @@ None.
# 0.1.0 (May 27, 2021)

- Initial release.

[CORS]: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
2 changes: 2 additions & 0 deletions tower-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ full = [
"auth",
"compression",
"compression-full",
"cors",
"decompression-full",
"follow-redirect",
"fs",
Expand All @@ -67,6 +68,7 @@ full = [

add-extension = []
auth = ["base64"]
cors = []
follow-redirect = ["iri-string", "tower/util"]
fs = ["tokio/fs", "tokio-util/io", "mime_guess", "mime", "percent-encoding"]
map-request-body = []
Expand Down
Loading

0 comments on commit c785742

Please sign in to comment.