Skip to content

Commit

Permalink
[#209]: fix: use bytes as values in proto to support non-utf8 payloads
Browse files Browse the repository at this point in the history
  • Loading branch information
rustatian authored Jan 13, 2025
2 parents 5b3219c + e2479e6 commit cd7bf49
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ jobs:
- name: Run linter
uses: golangci/[email protected] # Action page: <https://github.com/golangci/golangci-lint-action>
with:
version: v1.61 # without patch version
version: v1.62 # without patch version
only-new-issues: false # show only new issues if it's a pull request
args: --timeout=10m --build-tags=race ./...
2 changes: 1 addition & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
timeout-minutes: 60
strategy:
matrix:
php: [ "8.3" ]
php: [ "8.4" ]
go: [ stable ]
os: [ "ubuntu-latest" ]
steps:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/mholt/acmez v1.2.0
github.com/prometheus/client_golang v1.20.5
github.com/quic-go/quic-go v0.48.2
github.com/roadrunner-server/api/v4 v4.17.0
github.com/roadrunner-server/api/v4 v4.18.1
github.com/roadrunner-server/context v1.0.2
github.com/roadrunner-server/endure/v2 v2.6.1
github.com/roadrunner-server/errors v1.4.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ github.com/quic-go/qpack v0.5.1 h1:giqksBPnT/HDtZ6VhtFKgoLOWmlyo9Ei6u9PqzIMbhI=
github.com/quic-go/qpack v0.5.1/go.mod h1:+PC4XFrEskIVkcLzpEkbLqq1uCoxPhQuvK5rH1ZgaEg=
github.com/quic-go/quic-go v0.48.2 h1:wsKXZPeGWpMpCGSWqOcqpW2wZYic/8T3aqiOID0/KWE=
github.com/quic-go/quic-go v0.48.2/go.mod h1:yBgs3rWBOADpga7F+jJsb6Ybg1LSYiQvwWlLX+/6HMs=
github.com/roadrunner-server/api/v4 v4.17.0 h1:SVmqWfMCKcvjrpluk+mA1o1D8PT1uXHM6AWykFe6i0I=
github.com/roadrunner-server/api/v4 v4.17.0/go.mod h1:ALjb4nL64DM9Cm/vTyfWyGt1b3m1lO4fg11YUq6NrqY=
github.com/roadrunner-server/api/v4 v4.18.1 h1:IA01DjK7wPXkSAUc0Bg2d3hmc/XMI0DYn0BKbBju9bI=
github.com/roadrunner-server/api/v4 v4.18.1/go.mod h1:VdCLIpnjKFHNspqRlu5zfPvrDS9eLR7fYy5K9HYKNkE=
github.com/roadrunner-server/context v1.0.2 h1:MSK6mjG2KsFKS1IoieMrY9Ia7SGxDGh/tagpBQxi1SE=
github.com/roadrunner-server/context v1.0.2/go.mod h1:7d/DqP/2k9wLrop3AdC0gTilEeCvkrwBm4CVvAdkZR0=
github.com/roadrunner-server/endure/v2 v2.6.1 h1:vx+3ayn8HXnyeCcjKWwe+DfPrwL5sOQobugzCId4F7k=
Expand Down
29 changes: 29 additions & 0 deletions go.work.sum

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions handler/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ func convert(headers http.Header) map[string]*httpV1proto.HeaderValue {
if resp[k] == nil {
resp[k] = &httpV1proto.HeaderValue{}
}
resp[k].Value = append(resp[k].Value, v...)

for _, vv := range v {
resp[k].Value = append(resp[k].Value, []byte(vv))
}
}

return resp
Expand All @@ -35,7 +38,7 @@ func convertCookies(headers map[string]string) map[string]*httpV1proto.HeaderVal
resp[k] = &httpV1proto.HeaderValue{}
}

resp[k].Value = append(resp[k].Value, v)
resp[k].Value = append(resp[k].Value, []byte(v))
}

return resp
Expand Down
13 changes: 5 additions & 8 deletions handler/response.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package handler

import (
stderr "errors"
"fmt"
"net/http"
"strings"
Expand Down Expand Up @@ -55,7 +54,7 @@ func (h *Handler) handlePROTOresponse(pld *payload.Payload, w http.ResponseWrite

if pusher, ok := w.(http.Pusher); ok {
for i := 0; i < len(push); i++ {
err = pusher.Push(rsp.GetHeaders()[HTTP2Push].GetValue()[i], nil)
err = pusher.Push(string(rsp.GetHeaders()[HTTP2Push].GetValue()[i]), nil)
if err != nil {
return err
}
Expand All @@ -70,7 +69,7 @@ func (h *Handler) handlePROTOresponse(pld *payload.Payload, w http.ResponseWrite
// write all headers from the response to the writer
for k := range rsp.GetHeaders() {
for kk := range rsp.GetHeaders()[k].GetValue() {
w.Header().Add(k, rsp.GetHeaders()[k].GetValue()[kk])
w.Header().Add(k, string(rsp.GetHeaders()[k].GetValue()[kk]))
}
}

Expand All @@ -93,18 +92,16 @@ func (h *Handler) handlePROTOresponse(pld *payload.Payload, w http.ResponseWrite
return err
}

rw := http.NewResponseController(w) //nolint:bodyclose
err = rw.Flush()
if stderr.Is(err, http.ErrNotSupported) {
h.log.Warn("flushing is not supported by the response writer, using buffered writer")
if fl, ok := w.(http.Flusher); ok {
fl.Flush()
}

return nil
}

func handleProtoTrailers(h map[string]*httpV1proto.HeaderValue) {
for _, tr := range h[Trailer].GetValue() {
for _, n := range strings.Split(tr, ",") {
for _, n := range strings.Split(string(tr), ",") {
n = strings.Trim(n, "\t ")
if v, ok := h[n]; ok {
h["Trailer:"+n] = v
Expand Down
2 changes: 1 addition & 1 deletion tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ require (
github.com/prometheus/procfs v0.15.1 // indirect
github.com/quic-go/qpack v0.5.1 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/roadrunner-server/api/v4 v4.17.0 // indirect
github.com/roadrunner-server/api/v4 v4.18.1 // indirect
github.com/roadrunner-server/context v1.0.2 // indirect
github.com/roadrunner-server/errors v1.4.1 // indirect
github.com/roadrunner-server/events v1.0.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ github.com/quic-go/quic-go v0.48.2/go.mod h1:yBgs3rWBOADpga7F+jJsb6Ybg1LSYiQvwWl
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/roadrunner-server/api/v4 v4.17.0 h1:SVmqWfMCKcvjrpluk+mA1o1D8PT1uXHM6AWykFe6i0I=
github.com/roadrunner-server/api/v4 v4.17.0/go.mod h1:ALjb4nL64DM9Cm/vTyfWyGt1b3m1lO4fg11YUq6NrqY=
github.com/roadrunner-server/api/v4 v4.18.1 h1:IA01DjK7wPXkSAUc0Bg2d3hmc/XMI0DYn0BKbBju9bI=
github.com/roadrunner-server/api/v4 v4.18.1/go.mod h1:VdCLIpnjKFHNspqRlu5zfPvrDS9eLR7fYy5K9HYKNkE=
github.com/roadrunner-server/config/v5 v5.1.1 h1:2ciLPg9/U52WEx0263rxWfSigRsI/3LomNytE6Ld52E=
github.com/roadrunner-server/config/v5 v5.1.1/go.mod h1:7nm32rKEevspjkGSQWSqgbXkjeZEQffAbViq3Ekyx1I=
github.com/roadrunner-server/context v1.0.2 h1:MSK6mjG2KsFKS1IoieMrY9Ia7SGxDGh/tagpBQxi1SE=
Expand Down
2 changes: 1 addition & 1 deletion tests/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func TestHandler_Headers(t *testing.T) {

go func() {
err = hs.ListenAndServe()
if err != nil && !errors.Is(http.ErrServerClosed, err) {
if err != nil && !errors.Is(err, http.ErrServerClosed) {
t.Errorf("error listening the interface: error %v", err)
}
}()
Expand Down

0 comments on commit cd7bf49

Please sign in to comment.