Fix Access-Control-Expose-Headers header

This commit is contained in:
silverpill 2022-08-06 19:11:08 +00:00
parent 53ace3bf57
commit 450e47bcef
2 changed files with 6 additions and 3 deletions

View file

@ -1,5 +1,6 @@
use actix_cors::Cors;
use actix_web::{
http::header,
web,
App, HttpServer,
dev::Service,
@ -92,6 +93,11 @@ async fn main() -> std::io::Result<()> {
.allow_any_header()
},
};
let cors_config = cors_config
// Link header needs to be explicitly exposed
// because expose_any_header doesn't work
// https://github.com/actix/actix-extras/issues/192
.expose_headers(vec![header::LINK]);
let mut app = App::new()
.wrap(cors_config)
.wrap(ActixLogger::new("%r : %s : %{r}a"))

View file

@ -30,9 +30,6 @@ pub fn get_paginated_response(
);
HttpResponse::Ok()
.append_header(("Link", pagination_header))
// Link header needs to be exposed
// https://github.com/actix/actix-extras/issues/192
.append_header(("Access-Control-Expose-Headers", "Link"))
.json(items)
} else {
HttpResponse::Ok().json(items)