Skip to content

Commit 5b83219

Browse files
sean-cunniffemromaszewiczclaude
authored
fix: allow response error handler to set status code (#1963)
* fix: allow response error handler to set status code change the order the visit response body function sets the status code and content type so if an error occurs during json marshalling the response error handler can set the status code * fix: buffer JSON responses before writing headers JSON responses in strict server Visit*Response functions are now encoded to a bytes.Buffer before setting headers and calling WriteHeader. This ensures that if JSON encoding fails, nothing has been written to the ResponseWriter, allowing ResponseErrorHandlerFunc to set an appropriate status code (e.g. 500 instead of 200). Non-JSON content types (text, formdata, multipart, binary/io.Reader) retain the original headers-first ordering since their write patterns do not benefit from buffering. Adds regression tests for all content type paths and an integration test verifying that ResponseErrorHandlerFunc can set the status code when JSON encoding fails. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Address Greptile feedback Also buffer formdata responses before writing headers Apply the same marshal-before-headers pattern to Formdata responses: runtime.MarshalForm is called before setting Content-Type or calling WriteHeader, so if marshalling fails the error handler can still set an appropriate status code. Adds a regression test for the formdata encoding error path. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Marcin Romaszewicz <marcinr@gmail.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent a13ef41 commit 5b83219

File tree

22 files changed

+1482
-195
lines changed

22 files changed

+1482
-195
lines changed

internal/test/issues/issue-1093/api/child/child.gen.go

Lines changed: 7 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/test/issues/issue-1093/api/parent/parent.gen.go

Lines changed: 7 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/test/issues/issue-1208-1209/issue-multi-json.gen.go

Lines changed: 28 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/test/issues/issue-1212/pkg1/pkg1.gen.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/test/issues/issue-1378/bionicle/bionicle.gen.go

Lines changed: 14 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/test/issues/issue-1378/fooservice/fooservice.gen.go

Lines changed: 14 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/test/issues/issue-1529/strict-echo/issue1529.gen.go

Lines changed: 21 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/test/issues/issue-1676/ping.gen.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package: issue1963
2+
output: issue1963.gen.go
3+
generate:
4+
std-http-server: true
5+
strict-server: true
6+
models: true
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package issue1963
2+
3+
//go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config=config.yaml spec.yaml

0 commit comments

Comments
 (0)