Skip to content

Conversation

@Aum-Patel1234
Copy link

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

@codecov
Copy link

codecov bot commented Jan 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.00%. Comparing base (3dc1cd6) to head (24013a2).
⚠️ Report is 236 commits behind head on master.

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     
Flag Coverage Δ
?
--ldflags="-checklinkname=0" -tags sonic 99.00% <100.00%> (?)
-tags go_json 98.93% <100.00%> (?)
-tags nomsgpack 98.99% <100.00%> (?)
go-1.18 ?
go-1.19 ?
go-1.20 ?
go-1.21 ?
go-1.24 99.00% <100.00%> (?)
go-1.25 99.00% <100.00%> (?)
macos-latest 99.00% <100.00%> (-0.21%) ⬇️
ubuntu-latest 99.00% <100.00%> (-0.21%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@appleboy appleboy added this to the v1.12 milestone Jan 17, 2026
Copy link
Contributor

Copilot AI left a 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.PDF renderer that writes raw PDF bytes with Content-Type: application/pdf.
  • Add Context.PDF convenience method to render PDFs via Gin contexts.
  • Add unit test covering render.PDF header/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.

Comment on lines +1215 to +1219
// 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})
}
Copy link

Copilot AI Jan 24, 2026

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.

Copilot uses AI. Check for mistakes.
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for PDF content type

3 participants