-
Notifications
You must be signed in to change notification settings - Fork 8.5k
render: add PDF renderer and tests #4491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4491 +/- ##
==========================================
- Coverage 99.21% 99.00% -0.21%
==========================================
Files 42 45 +3
Lines 3182 3022 -160
==========================================
- Hits 3157 2992 -165
- Misses 17 21 +4
- Partials 8 9 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Adds first-class PDF response support by introducing a dedicated PDF renderer and a new Context.PDF helper, ensuring responses use the correct Content-Type.
Changes:
- Add
render.PDFrenderer that writes raw PDF bytes withContent-Type: application/pdf. - Add
Context.PDFconvenience method to render PDFs via Gin contexts. - Add unit test covering
render.PDFheader/body behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| render/render_test.go | Adds a unit test verifying render.PDF sets Content-Type and writes bytes correctly. |
| render/render.go | Registers PDF for compile-time Render interface compliance. |
| render/pdf.go | Introduces the render.PDF renderer implementation. |
| context.go | Adds Context.PDF helper to render PDF bytes with the correct content type. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // PDF writes the given PDF binary data into the response body. | ||
| // It also sets the Content-Type as "application/pdf". | ||
| func (c *Context) PDF(code int, data []byte) { | ||
| c.Render(code, render.PDF{Data: data}) | ||
| } |
Copilot
AI
Jan 24, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Context.PDF introduces a new public response helper but there are no corresponding tests in context_test.go. Other helpers (e.g., XML, Data) have both “normal” and StatusNoContent coverage to ensure body suppression still sets the correct Content-Type. Please add similar tests for PDF (including the 204/no-body case) to prevent regressions in header/body behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added the necessary tests in context_test.go
This PR adds a PDF renderer to the render package, allowing Gin to write
raw PDF bytes with the correct Content-Type.
Includes unit tests to verify header and body behavior.
Fixes #4456