armeria icon indicating copy to clipboard operation
armeria copied to clipboard

Fix a bug where CORS headers are not injected when a `ServerErrorHandler` is set

Open ikhoon opened this issue 1 year ago • 1 comments

Motivation:

ServerErrorHandler.renderStatus() is used in DefaultServerErrorHandler and may not be called in a custom ServerErrorHandler. Attempting to inject CORS headers via CorsServerErrorHandler.renderStatus() may not work.

Modifications:

  • Use ctx.mutateAdditionalResponseHeaders() to set CORS headers instead of mutating the response headers.
  • Store whether a CORS is set by CorsService to ctx.attr().
    • The value is used in CorsServerErrorHandler to set if missing

Result:

  • CORS headers for failed requests are now correctly set even when a custom ServerErrorHandler is configured.
  • Fixes #5493

ikhoon avatar Oct 14 '24 16:10 ikhoon

🔍 Build Scan® (commit: 806540290b692a57c44451e4502668d49120b07d)

Job name Status Build Scan®
build-ubicloud-standard-8-jdk-8 https://ge.armeria.dev/s/fazkthe3ihwae
build-ubicloud-standard-8-jdk-21-snapshot-blockhound https://ge.armeria.dev/s/67szeu7b6bgwk
build-ubicloud-standard-8-jdk-17-min-java-17-coverage https://ge.armeria.dev/s/byss46mekt4qg
build-ubicloud-standard-8-jdk-17-min-java-11 https://ge.armeria.dev/s/yc5gh2v74f4lw
build-ubicloud-standard-8-jdk-17-leak https://ge.armeria.dev/s/ulwpjvcbybspa
build-ubicloud-standard-8-jdk-11 https://ge.armeria.dev/s/6d4wvjvp2njtm
build-macos-12-jdk-21 https://ge.armeria.dev/s/dwxkaqdngnqqg

github-actions[bot] avatar Oct 14 '24 17:10 github-actions[bot]