Skip to content
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

Fix rendering #335

Merged
merged 3 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ require (
// Version v1.71.1 is breaking the build.
replace gopkg.in/DataDog/dd-trace-go.v1 v1.71.1 => gopkg.in/DataDog/dd-trace-go.v1 v1.67.1

// This version had to be pinned because the last few commits did not include any Go changes and it's likely
// the reason why 'go get -u ./...' is not bumping the version. But they're important because they include
// new C libraries used by lazypdf.
replace github.com/nitro/lazypdf/v2 v2.0.0-20250205120532-48aae54bfd96 => github.com/nitro/lazypdf/v2 v2.0.0-20250205171610-bfd709fec6cd
// lazypdf version needs to be pinned as well because of the dd-trace-go version pinning which prevents the lazypdf version from being
// updated.
replace github.com/nitro/lazypdf/v2 v2.0.0-20250205120532-48aae54bfd96 => github.com/nitro/lazypdf/v2 v2.0.0-20250206115348-1829ea1fd728
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mitchellh/mapstructure v1.5.1-0.20231216201459-8508981c8b6c h1:cqn374mizHuIWj+OSJCajGr/phAmuMug9qIX3l9CflE=
github.com/mitchellh/mapstructure v1.5.1-0.20231216201459-8508981c8b6c/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/nitro/lazypdf/v2 v2.0.0-20250205171610-bfd709fec6cd h1:iNpUVFqOQHdmySemiibLm6r1qY5qYSIExP2+bm7M280=
github.com/nitro/lazypdf/v2 v2.0.0-20250205171610-bfd709fec6cd/go.mod h1:cAh1CSLNZXNh+PizhypjyoEyWz2cSjcGKe9EUBhEfxA=
github.com/nitro/lazypdf/v2 v2.0.0-20250206115348-1829ea1fd728 h1:lYbrSO6dULPPxdTBI/mwM+do3M7g1BtcNNtOYGleWA8=
github.com/nitro/lazypdf/v2 v2.0.0-20250206115348-1829ea1fd728/go.mod h1:cAh1CSLNZXNh+PizhypjyoEyWz2cSjcGKe9EUBhEfxA=
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
github.com/outcaste-io/ristretto v0.2.3 h1:AK4zt/fJ76kjlYObOeNwh4T3asEuaCmp26pOvUOL9w0=
Expand Down
2 changes: 1 addition & 1 deletion internal/service/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (w *Worker) Process(
}

storage := bytes.NewBuffer([]byte{})
dpi := 96
dpi := 72
//nolint:gosec,G115
err = lazypdf.SaveToPNG(ctx, uint16(page), uint16(width), scale, dpi, bytes.NewBuffer(payload), storage)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion internal/transport/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,14 @@ func (h handler) metadata(w http.ResponseWriter, r *http.Request) {

// Remove all the parameters, but the token and page, from the path. Other parameters can then be passed to the service
// without making the url signature invalid.
func (h handler) urlToVerify(r *http.Request) string {
func (handler) urlToVerify(r *http.Request) string {
q := r.URL.Query()
for key := range q {
if key == "page" || key == "token" {
continue
}
q.Del(key)
}
r.URL.RawQuery = q.Encode()
return r.URL.String()
}
46 changes: 46 additions & 0 deletions internal/transport/handler_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package transport

import (
"fmt"
"net/http"
"testing"

"github.com/stretchr/testify/require"
)

func TestHandlerURLToVerify(t *testing.T) {
tests := []struct {
path string
expected string
}{
{
path: "/path",
expected: "/path",
},
{
path: "/path?page=1",
expected: "/path?page=1",
},
{
path: "/path?token=2",
expected: "/path?token=2",
},
{
path: "/path?page=1&token=2",
expected: "/path?page=1&token=2",
},
{
path: "/path?page=1&token=2&scale=3&width=4",
expected: "/path?page=1&token=2",
},
}
for i, tt := range tests {
t.Run(fmt.Sprintf("Scenario %d", i), func(t *testing.T) {
t.Parallel()
var h handler
req, err := http.NewRequest(http.MethodGet, tt.path, nil)
require.NoError(t, err)
require.Equal(t, tt.expected, h.urlToVerify(req))
})
}
}