Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #137 from 0xProject/marcin/bugfix
Browse files Browse the repository at this point in the history
fix: run gunzip only otherwise pass through
  • Loading branch information
eitu5ami authored Dec 11, 2023
2 parents bb44fd7 + 9f2cb5a commit ee7aba7
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 119 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/golang.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ jobs:
run: docker-compose up -d
- name: Run tests
run: go test -race -shuffle=on -v ./internal/...
env:
RPC_GATEWAY_NODE_URL_1: ${{ secrets.RPC_GATEWAY_NODE_URL_1 }}
RPC_GATEWAY_NODE_URL_2: ${{ secrets.RPC_GATEWAY_NODE_URL_2 }}
- name: Print out docker containers' logs
if: always()
run: docker-compose logs
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.21-alpine3.18 AS builder
FROM golang:1.21-alpine3.19 AS builder

RUN apk add --update-cache \
git \
Expand Down
43 changes: 0 additions & 43 deletions internal/middleware/gzip.go

This file was deleted.

65 changes: 0 additions & 65 deletions internal/middleware/gzip_test.go

This file was deleted.

8 changes: 5 additions & 3 deletions internal/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import (
"io"
"net/http"
"net/http/httputil"
"strings"
"time"

"github.com/0xProject/rpc-gateway/internal/middleware"
"github.com/go-http-utils/headers"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
Expand Down Expand Up @@ -113,10 +115,10 @@ func (h *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
pw := NewResponseWriter()
r.Body = io.NopCloser(bytes.NewBuffer(body.Bytes()))

if target.Config.Connection.HTTP.Compression {
middleware.Gzip(target.Proxy).ServeHTTP(pw, r)
} else {
if !target.Config.Connection.HTTP.Compression && strings.Contains(r.Header.Get(headers.ContentEncoding), "gzip") {
middleware.Gunzip(target.Proxy).ServeHTTP(pw, r)
} else {
target.Proxy.ServeHTTP(pw, r)
}

if h.HasNodeProviderFailed(pw.statusCode) {
Expand Down
10 changes: 3 additions & 7 deletions internal/rpcgateway/rpcgateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,7 @@ func TestRpcGatewayFailover(t *testing.T) {
MaxConnsPerHost: 1,
}

t.Logf("gateway serving from: %s", gs.URL)

req, _ := http.NewRequest("POST", gs.URL, bytes.NewBufferString(``))
req, _ := http.NewRequest("POST", gs.URL, bytes.NewBufferString(rpcRequestBody))
req.Header.Set("Content-Type", "application/json")
req.ContentLength = int64(len(rpcRequestBody))

Expand All @@ -131,10 +129,8 @@ func TestRpcGatewayFailover(t *testing.T) {

assert.Equal(t, http.StatusOK, res.StatusCode)

bodyContent, _ := io.ReadAll(res.Body)

t.Log("Response from RPC gateway:")
t.Logf("%s", bodyContent)
_, err = io.ReadAll(res.Body)
assert.Nil(t, err)

err = gateway.Stop(context.TODO())
assert.Nil(t, err)
Expand Down

0 comments on commit ee7aba7

Please sign in to comment.