Skip to content

Conversation

@djken2009
Copy link

…s (#7763)

This commit fixes Issue #7763 where reloading the Swagger UI page causes intermittent 500 Internal Server Error responses with the message: "requirement failed: Responses with this status code must have an empty entity"

Root Cause:

Akka HTTP 10.1.15's getFromResource method returns 304 Not Modified responses with non-empty entities, which violates RFC 7232 Section 4.1. The issue is triggered when mapResponseEntity attempts to transform the entity content (replacing Swagger URLs), causing HttpResponse validation to fail because 304 responses must have empty entities.

The error was particularly visible in Chrome-based browsers when using the refresh button (Ctrl+R/F5), as Chrome sends conditional requests (If-None-Match headers) even with Cache-Control: no-cache.

Solution:

Intercept the response from getFromResource before any entity transformation. Check if the status is 304 Not Modified and ensure the entity is empty before attempting any content transformation. For 200 OK responses, apply the normal URL replacement logic.

Changes made in SwaggerUiHttpService.scala:

Modified serveIndex method (lines 26-46):

  • Wrap getFromResource with mapResponse to check response status first
  • If status is 304: set entity to Empty immediately, skip content transformation
  • If status is 200: apply entity transformation (URL/layout replacement)
  • This ensures 304 responses are handled correctly before mapEntity processes them

Fixes #7763

Description

Release Notes Confirmation

CHANGELOG.md

  • I updated CHANGELOG.md in this PR
  • I assert that this change shouldn't be included in CHANGELOG.md because it doesn't impact community users

Terra Release Notes

  • I added a suggested release notes entry in this Jira ticket
  • I assert that this change doesn't need Jira release notes because it doesn't impact Terra users

broadinstitute#7763)

This commit fixes Issue broadinstitute#7763 where reloading the Swagger UI page causes
intermittent 500 Internal Server Error responses with the message:
"requirement failed: Responses with this status code must have an empty entity"

Root Cause:
-----------
Akka HTTP 10.1.15's `getFromResource` method returns 304 Not Modified responses
with non-empty entities, which violates RFC 7232 Section 4.1. The issue is
triggered when `mapResponseEntity` attempts to transform the entity content
(replacing Swagger URLs), causing HttpResponse validation to fail because 304
responses must have empty entities.

The error was particularly visible in Chrome-based browsers when using the
refresh button (Ctrl+R/F5), as Chrome sends conditional requests (If-None-Match
headers) even with Cache-Control: no-cache.

Solution:
---------
Intercept the response from `getFromResource` before any entity transformation.
Check if the status is 304 Not Modified and ensure the entity is empty before
attempting any content transformation. For 200 OK responses, apply the normal
URL replacement logic.

Changes made in SwaggerUiHttpService.scala:

Modified serveIndex method (lines 26-46):
  - Wrap getFromResource with mapResponse to check response status first
  - If status is 304: set entity to Empty immediately, skip content transformation
  - If status is 200: apply entity transformation (URL/layout replacement)
  - This ensures 304 responses are handled correctly before mapEntity processes them

Fixes broadinstitute#7763
@djken2009 djken2009 requested a review from a team as a code owner November 8, 2025 10:09
@aednichols aednichols changed the title Fix Swagger UI index.html 304 Not Modified response causing 500 error… AN-796 Fix Swagger UI 500 errors Nov 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reloading swagger page causes 500 error.

1 participant