mirror of
https://github.com/telanflow/mps.git
synced 2025-09-26 20:41:25 +08:00
update minimum Go version v1.16
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/telanflow/mps"
|
||||
"github.com/telanflow/mps/middleware"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/telanflow/mps"
|
||||
"github.com/telanflow/mps/middleware"
|
||||
)
|
||||
|
||||
// A simple BasicAuth example
|
||||
@@ -68,6 +69,6 @@ func main() {
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, _ := ioutil.ReadAll(resp.Body)
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
log.Println(string(body))
|
||||
}
|
||||
|
@@ -1,13 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/telanflow/mps"
|
||||
"github.com/telanflow/mps/middleware"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/telanflow/mps"
|
||||
"github.com/telanflow/mps/middleware"
|
||||
)
|
||||
|
||||
// A simple example of cascading proxy.
|
||||
@@ -56,7 +57,7 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
body, _ := ioutil.ReadAll(resp.Body)
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
resp.Body.Close()
|
||||
|
||||
log.Println(resp.Header)
|
||||
|
@@ -15,7 +15,7 @@ for example:
|
||||
```go
|
||||
func main() {
|
||||
// Load ca.crt file
|
||||
certPEMBlock, err := ioutil.ReadFile("ca.crt")
|
||||
certPEMBlock, err := os.ReadFile("ca.crt")
|
||||
if err != nil {
|
||||
panic("failed to load ca.crt file")
|
||||
}
|
||||
|
@@ -2,11 +2,12 @@ package mps
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/telanflow/mps/pool"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"strconv"
|
||||
|
||||
"github.com/telanflow/mps/pool"
|
||||
)
|
||||
|
||||
// ForwardHandler The forward proxy type. Implements http.Handler.
|
||||
|
@@ -1,13 +1,14 @@
|
||||
package mps
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewForwardHandler_ContentLength(t *testing.T) {
|
||||
@@ -26,12 +27,12 @@ func TestNewForwardHandler_ContentLength(t *testing.T) {
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, _ := ioutil.ReadAll(resp.Body)
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
bodySize := len(body)
|
||||
contentLength, _ := strconv.Atoi(resp.Header.Get("Content-Length"))
|
||||
|
||||
asserts := assert.New(t)
|
||||
asserts.Equal(resp.StatusCode, 200, "statusCode should be equal 200")
|
||||
asserts.Equal(bodySize, contentLength, "Content-Length should be equal " + strconv.Itoa(bodySize))
|
||||
asserts.Equal(bodySize, contentLength, "Content-Length should be equal "+strconv.Itoa(bodySize))
|
||||
asserts.Equal(int64(bodySize), resp.ContentLength)
|
||||
}
|
||||
|
6
go.mod
6
go.mod
@@ -1,10 +1,8 @@
|
||||
module github.com/telanflow/mps
|
||||
|
||||
go 1.14
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/gorilla/websocket v1.5.0
|
||||
github.com/stretchr/testify v1.7.1
|
||||
gopkg.in/yaml.v3 v3.0.0 // indirect
|
||||
github.com/stretchr/testify v1.8.4
|
||||
)
|
||||
|
10
go.sum
10
go.sum
@@ -6,10 +6,14 @@ github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA=
|
||||
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
@@ -2,12 +2,13 @@ package mps
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func newTestServer() *httptest.Server {
|
||||
@@ -46,7 +47,7 @@ func TestNewHttpProxy(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
body, _ := ioutil.ReadAll(resp.Body)
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
resp.Body.Close()
|
||||
|
||||
asserts := assert.New(t)
|
||||
@@ -71,7 +72,7 @@ func TestMiddlewareFunc(t *testing.T) {
|
||||
|
||||
var buf bytes.Buffer
|
||||
buf.WriteString("middleware")
|
||||
resp.Body = ioutil.NopCloser(&buf)
|
||||
resp.Body = io.NopCloser(&buf)
|
||||
|
||||
//
|
||||
// You have to reset Content-Length, if you change the Body.
|
||||
@@ -91,7 +92,7 @@ func TestMiddlewareFunc(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
body, _ := ioutil.ReadAll(resp.Body)
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
resp.Body.Close()
|
||||
|
||||
asserts := assert.New(t)
|
||||
|
@@ -3,10 +3,11 @@ package middleware
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"github.com/telanflow/mps"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/telanflow/mps"
|
||||
)
|
||||
|
||||
// proxy Authorization header
|
||||
@@ -88,7 +89,7 @@ func BasicUnauthorized(req *http.Request, realm string) *http.Response {
|
||||
"Proxy-Authenticate": []string{"Basic realm=" + realm},
|
||||
"Proxy-Connection": []string{"close"},
|
||||
},
|
||||
Body: ioutil.NopCloser(bytes.NewBuffer([]byte(unauthorizedMsg))),
|
||||
Body: io.NopCloser(bytes.NewBuffer([]byte(unauthorizedMsg))),
|
||||
ContentLength: int64(len(unauthorizedMsg)),
|
||||
}
|
||||
}
|
||||
|
@@ -11,11 +11,9 @@ import (
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"crypto/x509/pkix"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/telanflow/mps/cert"
|
||||
"github.com/telanflow/mps/pool"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
"math/rand"
|
||||
"net"
|
||||
@@ -27,6 +25,9 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/telanflow/mps/cert"
|
||||
"github.com/telanflow/mps/pool"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -96,7 +97,7 @@ func (mitm *MitmHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||
// execution middleware
|
||||
ctx := mitm.Ctx.WithRequest(req)
|
||||
resp, err := ctx.Next(req)
|
||||
if err != nil && err != MethodNotSupportErr {
|
||||
if err != nil && !errors.Is(err, MethodNotSupportErr) {
|
||||
if resp != nil {
|
||||
copyHeaders(rw.Header(), resp.Header, mitm.Ctx.KeepDestinationHeaders)
|
||||
rw.WriteHeader(resp.StatusCode)
|
||||
@@ -185,7 +186,7 @@ func (mitm *MitmHandler) transmit(clientConn net.Conn, originalReq *http.Request
|
||||
// reset Content-Length
|
||||
resp.ContentLength = bufferSize
|
||||
resp.Header.Set("Content-Length", strconv.Itoa(int(bufferSize)))
|
||||
resp.Body = ioutil.NopCloser(buffer)
|
||||
resp.Body = io.NopCloser(buffer)
|
||||
err = resp.Write(rawClientTls)
|
||||
if err != nil {
|
||||
return
|
||||
|
@@ -3,13 +3,14 @@ package mps
|
||||
import (
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/telanflow/mps/cert"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/telanflow/mps/cert"
|
||||
)
|
||||
|
||||
func TestNewMitmHandler(t *testing.T) {
|
||||
@@ -41,7 +42,7 @@ func TestNewMitmHandler(t *testing.T) {
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, _ := ioutil.ReadAll(resp.Body)
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
|
||||
asserts := assert.New(t)
|
||||
asserts.Equal(resp.StatusCode, 200, "response status code not equal 200")
|
||||
|
@@ -2,11 +2,12 @@ package mps
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/telanflow/mps/pool"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"strconv"
|
||||
|
||||
"github.com/telanflow/mps/pool"
|
||||
)
|
||||
|
||||
// ReverseHandler is a reverse proxy server implementation
|
||||
|
@@ -1,13 +1,14 @@
|
||||
package mps
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewReverseHandler(t *testing.T) {
|
||||
@@ -26,12 +27,12 @@ func TestNewReverseHandler(t *testing.T) {
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, _ := ioutil.ReadAll(resp.Body)
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
bodySize := len(body)
|
||||
contentLength, _ := strconv.Atoi(resp.Header.Get("Content-Length"))
|
||||
|
||||
asserts := assert.New(t)
|
||||
asserts.Equal(resp.StatusCode, 200, "statusCode should be equal 200")
|
||||
asserts.Equal(bodySize, contentLength, "Content-Length should be equal " + strconv.Itoa(bodySize))
|
||||
asserts.Equal(bodySize, contentLength, "Content-Length should be equal "+strconv.Itoa(bodySize))
|
||||
asserts.Equal(int64(bodySize), resp.ContentLength)
|
||||
}
|
||||
|
@@ -2,7 +2,6 @@ package mps
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/telanflow/mps/pool"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -10,6 +9,8 @@ import (
|
||||
"net/url"
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
"github.com/telanflow/mps/pool"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@@ -1,11 +1,12 @@
|
||||
package mps
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewTunnelHandler(t *testing.T) {
|
||||
|
@@ -3,7 +3,6 @@ package mps
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"github.com/telanflow/mps/pool"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -11,6 +10,8 @@ import (
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/telanflow/mps/pool"
|
||||
)
|
||||
|
||||
// WebsocketHandler The websocket proxy type. Implements http.Handler.
|
||||
|
@@ -1,13 +1,14 @@
|
||||
package mps
|
||||
|
||||
import (
|
||||
"github.com/gorilla/websocket"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
var upgrader = websocket.Upgrader{}
|
||||
|
Reference in New Issue
Block a user