summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/ci-build.yml19
-rw-r--r--.travis.yml76
-rw-r--r--README.md2
-rw-r--r--service/container_test.go2
-rw-r--r--service/gzip/service.go2
-rw-r--r--service/gzip/service_test.go53
-rw-r--r--service/http/constants.go6
-rw-r--r--service/http/response.go29
-rw-r--r--service/http/response_test.go25
-rw-r--r--service/http/ssl_test.go2
-rw-r--r--tests/http/push.php2
11 files changed, 80 insertions, 138 deletions
diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml
index 339c841a..cf63195c 100644
--- a/.github/workflows/ci-build.yml
+++ b/.github/workflows/ci-build.yml
@@ -1,10 +1,6 @@
name: CI
-on:
- push:
- branches: '**'
- tags: '**'
- pull_request:
+on: [push, pull_request]
jobs:
build:
@@ -14,7 +10,7 @@ jobs:
fail-fast: false
matrix:
php: [7.1, 7.2, 7.3, 7.4]
- go: [1.12]
+ go: [1.12, 1.13]
env:
GO111MODULE: on
steps:
@@ -103,6 +99,17 @@ jobs:
./codecov-bash -f health.txt
fi
+ golangci-check:
+ name: runner / golangci-lint
+ runs-on: ubuntu-latest
+ steps:
+ - name: Check out code into the Go module directory
+ uses: actions/checkout@v1
+ - name: golangci-lint
+ uses: reviewdog/action-golangci-lint@v1
+ with:
+ github_token: ${{ secrets.github_token }}
+
image:
name: Build docker image
runs-on: ubuntu-latest
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index a501f7ce..00000000
--- a/.travis.yml
+++ /dev/null
@@ -1,76 +0,0 @@
-dist: xenial
-language: go
-sudo: required
-
-go:
- - "1.12.x"
-
-install:
- - export GO111MODULE=on
- - go mod download
- - php -v
- - php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
- - php composer-setup.php
- - php composer.phar install --no-interaction --prefer-source
- - find src/ -name "*.php" -print0 | xargs -0 -n1 -P8 php -l
- - composer analyze
- - chmod +x bin/rr && bin/rr get-binary
-
-script:
- - go test -race -v -coverprofile=lib.txt -covermode=atomic
- - go test ./util -race -v -coverprofile=util.txt -covermode=atomic
- - go test ./service -race -v -coverprofile=service.txt -covermode=atomic
- - go test ./service/env -race -v -coverprofile=env.txt -covermode=atomic
- - go test ./service/rpc -race -v -coverprofile=rpc.txt -covermode=atomic
- - go test ./service/http -race -v -coverprofile=http.txt -covermode=atomic
- - go test ./service/static -race -v -coverprofile=static.txt -covermode=atomic
- - go test ./service/limit -race -v -coverprofile=limit.txt -covermode=atomic
- - go test ./service/headers -race -v -coverprofile=headers.txt -covermode=atomic
- - go test ./service/metrics -race -v -coverprofile=metrics.txt -covermode=atomic
- - go test ./service/health -race -v -coverprofile=health.txt -covermode=atomic
-
-after_success:
- - curl https://codecov.io/bash -o codecov-bash
- - chmod +x codecov-bash
- - ./codecov-bash -f lib.txt
- - ./codecov-bash -f util.txt
- - ./codecov-bash -f service.txt
- - ./codecov-bash -f env.txt
- - ./codecov-bash -f rpc.txt
- - ./codecov-bash -f http.txt
- - ./codecov-bash -f static.txt
- - ./codecov-bash -f limit.txt
- - ./codecov-bash -f headers.txt
- - ./codecov-bash -f metrics.txt
- - ./codecov-bash -f health.txt
-
-jobs:
- include:
- - stage: Test
- env: "PHP=7.1"
- before_install:
- - sudo add-apt-repository -y ppa:ondrej/php
- - sudo apt-get update
- - sudo apt-get install -y php7.1-cli php7.1-curl
- - sudo cp `which php7.1` `which php`
- - stage: Test
- env: "PHP=7.2"
- before_install:
- - sudo add-apt-repository -y ppa:ondrej/php
- - sudo apt-get update
- - sudo apt-get install -y php7.2-cli php7.2-curl
- - sudo cp `which php7.2` `which php`
- - stage: Test
- env: "PHP=7.3"
- before_install:
- - sudo add-apt-repository -y ppa:ondrej/php
- - sudo apt-get update
- - sudo apt-get install -y php7.3-cli php7.3-curl
- - sudo cp `which php7.3` `which php`
- - stage: Test
- env: "PHP=7.4"
- before_install:
- - sudo add-apt-repository -y ppa:ondrej/php
- - sudo apt-get update
- - sudo apt-get install -y php7.4-cli php7.4-curl
- - sudo cp `which php7.4` `which php`
diff --git a/README.md b/README.md
index 4dfd1b46..5852c022 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@
<p align="center">
<a href="https://packagist.org/packages/spiral/roadrunner"><img src="https://poser.pugx.org/spiral/roadrunner/version"></a>
<a href="https://godoc.org/github.com/spiral/roadrunner"><img src="https://godoc.org/github.com/spiral/roadrunner?status.svg"></a>
- <a href="https://travis-ci.org/spiral/roadrunner"><img src="https://travis-ci.org/spiral/roadrunner.svg?branch=master"></a>
+ <a href="https://github.com/spiral/roadrunner"><img src="https://github.com/spiral/roadrunner/workflows/CI/badge.svg" alt=""></a>
<a href="https://goreportcard.com/report/github.com/spiral/roadrunner"><img src="https://goreportcard.com/badge/github.com/spiral/roadrunner"></a>
<a href="https://scrutinizer-ci.com/g/spiral/roadrunner/?branch=master"><img src="https://scrutinizer-ci.com/g/spiral/roadrunner/badges/quality-score.png"></a>
<a href="https://codecov.io/gh/spiral/roadrunner/"><img src="https://codecov.io/gh/spiral/roadrunner/branch/master/graph/badge.svg"></a>
diff --git a/service/container_test.go b/service/container_test.go
index ad4c1e64..9860777f 100644
--- a/service/container_test.go
+++ b/service/container_test.go
@@ -457,7 +457,7 @@ func TestContainer_NoInit(t *testing.T) {
}
type testInitD struct {
- c *testInitC
+ c *testInitC //nolint:golint,unused,structcheck
}
type DCfg struct {
diff --git a/service/gzip/service.go b/service/gzip/service.go
index 86069c2f..bb6bcfcd 100644
--- a/service/gzip/service.go
+++ b/service/gzip/service.go
@@ -16,7 +16,7 @@ type Service struct {
func (s *Service) Init(cfg *Config, r *rrhttp.Service) (bool, error) {
s.cfg = cfg
- if s.cfg.Enable == false {
+ if !s.cfg.Enable {
return false, nil
}
diff --git a/service/gzip/service_test.go b/service/gzip/service_test.go
index 6a2ee382..9801860f 100644
--- a/service/gzip/service_test.go
+++ b/service/gzip/service_test.go
@@ -7,16 +7,13 @@ import (
"github.com/spiral/roadrunner/service"
rrhttp "github.com/spiral/roadrunner/service/http"
"github.com/stretchr/testify/assert"
- "io/ioutil"
- "net/http"
- "os"
"testing"
)
type testCfg struct {
gzip string
httpCfg string
- static string
+ //static string
target string
}
@@ -34,24 +31,24 @@ func (cfg *testCfg) Unmarshal(out interface{}) error {
return json.Unmarshal([]byte(cfg.target), out)
}
-func get(url string) (string, *http.Response, error) {
- r, err := http.Get(url)
- if err != nil {
- return "", nil, err
- }
-
- b, err := ioutil.ReadAll(r.Body)
- if err != nil {
- return "", nil, err
- }
-
- err = r.Body.Close()
- if err != nil {
- return "", nil, err
- }
-
- return string(b), r, err
-}
+//func get(url string) (string, *http.Response, error) {
+// r, err := http.Get(url)
+// if err != nil {
+// return "", nil, err
+// }
+//
+// b, err := ioutil.ReadAll(r.Body)
+// if err != nil {
+// return "", nil, err
+// }
+//
+// err = r.Body.Close()
+// if err != nil {
+// return "", nil, err
+// }
+//
+// return string(b), r, err
+//}
func Test_Disabled(t *testing.T) {
logger, _ := test.NewNullLogger()
@@ -115,9 +112,9 @@ func Test_Disabled(t *testing.T) {
// //header should contain content-encoding:gzip because content-length > gziphandler.DefaultMinSize
// }
-func tmpDir() string {
- p := os.TempDir()
- r, _ := json.Marshal(p)
-
- return string(r)
-}
+//func tmpDir() string {
+// p := os.TempDir()
+// r, _ := json.Marshal(p)
+//
+// return string(r)
+//}
diff --git a/service/http/constants.go b/service/http/constants.go
new file mode 100644
index 00000000..a25f52a4
--- /dev/null
+++ b/service/http/constants.go
@@ -0,0 +1,6 @@
+package http
+
+import "net/http"
+
+var http2pushHeaderKey = http.CanonicalHeaderKey("http2-push")
+var trailerHeaderKey = http.CanonicalHeaderKey("trailer")
diff --git a/service/http/response.go b/service/http/response.go
index aafaed13..16434a7c 100644
--- a/service/http/response.go
+++ b/service/http/response.go
@@ -33,7 +33,8 @@ func NewResponse(p *roadrunner.Payload) (*Response, error) {
// Write writes response headers, status and body into ResponseWriter.
func (r *Response) Write(w http.ResponseWriter) error {
- p, h := handlePushHeaders(r.Headers)
+ // INFO map is the reference type in golang
+ p := handlePushHeaders(r.Headers)
if pusher, ok := w.(http.Pusher); ok {
for _, v := range p {
err := pusher.Push(v, nil)
@@ -43,7 +44,7 @@ func (r *Response) Write(w http.ResponseWriter) error {
}
}
- h = handleTrailers(h)
+ handleTrailers(r.Headers)
for n, h := range r.Headers {
for _, v := range h {
w.Header().Add(n, v)
@@ -68,26 +69,24 @@ func (r *Response) Write(w http.ResponseWriter) error {
return nil
}
-func handlePushHeaders(h map[string][]string) ([]string, map[string][]string) {
+func handlePushHeaders(h map[string][]string) []string {
var p []string
- pushHeader, ok := h["http2-push"]
+ pushHeader, ok := h[http2pushHeaderKey]
if !ok {
- return p, h
+ return p
}
- for _, v := range pushHeader {
- p = append(p, v)
- }
+ p = append(p, pushHeader...)
- delete(h, "http2-push")
+ delete(h, http2pushHeaderKey)
- return p, h
+ return p
}
-func handleTrailers(h map[string][]string) map[string][]string {
- trailers, ok := h["trailer"]
+func handleTrailers(h map[string][]string) {
+ trailers, ok := h[trailerHeaderKey]
if !ok {
- return h
+ return
}
for _, tr := range trailers {
@@ -101,7 +100,5 @@ func handleTrailers(h map[string][]string) map[string][]string {
}
}
- delete(h, "trailer")
-
- return h
+ delete(h, trailerHeaderKey)
}
diff --git a/service/http/response_test.go b/service/http/response_test.go
index ad524567..1f394276 100644
--- a/service/http/response_test.go
+++ b/service/http/response_test.go
@@ -71,6 +71,11 @@ func TestNewResponse_Stream(t *testing.T) {
Context: []byte(`{"headers":{"key":["value"]},"status": 301}`),
})
+ // r is pointer, so, it might be nil
+ if r == nil {
+ t.Fatal("response is nil")
+ }
+
r.body = &bytes.Buffer{}
r.body.(*bytes.Buffer).WriteString("hello world")
@@ -90,6 +95,11 @@ func TestNewResponse_StreamError(t *testing.T) {
Context: []byte(`{"headers":{"key":["value"]},"status": 301}`),
})
+ // r is pointer, so, it might be nil
+ if r == nil {
+ t.Fatal("response is nil")
+ }
+
r.body = &bytes.Buffer{}
r.body.(*bytes.Buffer).WriteString("hello world")
@@ -102,7 +112,7 @@ func TestNewResponse_StreamError(t *testing.T) {
func TestWrite_HandlesPush(t *testing.T) {
r, err := NewResponse(&roadrunner.Payload{
- Context: []byte(`{"headers":{"http2-push":["/test.js"],"content-type":["text/html"]},"status": 200}`),
+ Context: []byte(`{"headers":{"Http2-Push":["/test.js"],"content-type":["text/html"]},"status": 200}`),
})
assert.NoError(t, err)
@@ -111,13 +121,13 @@ func TestWrite_HandlesPush(t *testing.T) {
w := &testWriter{h: http.Header(make(map[string][]string))}
assert.NoError(t, r.Write(w))
- assert.Nil(t, w.h["http2-push"])
+ assert.Nil(t, w.h["Http2-Push"])
assert.Equal(t, []string{"/test.js"}, w.pushes)
}
func TestWrite_HandlesTrailers(t *testing.T) {
r, err := NewResponse(&roadrunner.Payload{
- Context: []byte(`{"headers":{"trailer":["foo, bar", "baz"],"foo":["test"],"bar":["demo"]},"status": 200}`),
+ Context: []byte(`{"headers":{"Trailer":["foo, bar", "baz"],"foo":["test"],"bar":["demo"]},"status": 200}`),
})
assert.NoError(t, err)
@@ -126,9 +136,10 @@ func TestWrite_HandlesTrailers(t *testing.T) {
w := &testWriter{h: http.Header(make(map[string][]string))}
assert.NoError(t, r.Write(w))
- assert.Nil(t, w.h["trailer"])
- assert.Nil(t, w.h["foo"])
- assert.Nil(t, w.h["baz"])
+ assert.Nil(t, w.h[trailerHeaderKey])
+ assert.Nil(t, w.h["foo"]) //nolint:golint,staticcheck
+ assert.Nil(t, w.h["baz"]) //nolint:golint,staticcheck
+
assert.Equal(t, "test", w.h.Get("Trailer:foo"))
assert.Equal(t, "demo", w.h.Get("Trailer:bar"))
}
@@ -136,7 +147,7 @@ func TestWrite_HandlesTrailers(t *testing.T) {
func TestWrite_HandlesHandlesWhitespacesInTrailer(t *testing.T) {
r, err := NewResponse(&roadrunner.Payload{
Context: []byte(
- `{"headers":{"trailer":["foo\t,bar , baz"],"foo":["a"],"bar":["b"],"baz":["c"]},"status": 200}`),
+ `{"headers":{"Trailer":["foo\t,bar , baz"],"foo":["a"],"bar":["b"],"baz":["c"]},"status": 200}`),
})
assert.NoError(t, err)
diff --git a/service/http/ssl_test.go b/service/http/ssl_test.go
index c9b4d090..49bba6cb 100644
--- a/service/http/ssl_test.go
+++ b/service/http/ssl_test.go
@@ -247,7 +247,7 @@ func Test_SSL_Service_Push(t *testing.T) {
b, err := ioutil.ReadAll(r.Body)
assert.NoError(t, err)
- assert.Equal(t, "", r.Header.Get("http2-push"))
+ assert.Equal(t, "", r.Header.Get("Http2-Push"))
assert.NoError(t, err)
assert.Equal(t, 201, r.StatusCode)
diff --git a/tests/http/push.php b/tests/http/push.php
index efe9eeda..d88fc076 100644
--- a/tests/http/push.php
+++ b/tests/http/push.php
@@ -6,5 +6,5 @@ use \Psr\Http\Message\ResponseInterface;
function handleRequest(ServerRequestInterface $req, ResponseInterface $resp): ResponseInterface
{
$resp->getBody()->write(strtoupper($req->getQueryParams()['hello']));
- return $resp->withAddedHeader("http2-push", __FILE__)->withStatus(201);
+ return $resp->withAddedHeader("Http2-Push", __FILE__)->withStatus(201);
}