Skip to content

Commit

Permalink
Merge pull request #292 from whilei/gofmt-2018-Jun-16-23-20
Browse files Browse the repository at this point in the history
gofmt
  • Loading branch information
elazarl authored Jul 25, 2018
2 parents a0c9541 + 63b166f commit 947c36d
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 28 deletions.
2 changes: 1 addition & 1 deletion ext/html/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"net/http"
"strings"

"github.com/elazarl/goproxy"
"github.com/rogpeppe/go-charset/charset"
_ "github.com/rogpeppe/go-charset/data"
"github.com/elazarl/goproxy"
)

var IsHtml goproxy.RespCondition = goproxy.ContentTypeIs("text/html")
Expand Down
4 changes: 2 additions & 2 deletions ext/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package goproxy_image

import (
"bytes"
. "github.com/elazarl/goproxy"
"github.com/elazarl/goproxy/regretable"
"image"
_ "image/gif"
"image/jpeg"
"image/png"
"io/ioutil"
"net/http"
. "github.com/elazarl/goproxy"
"github.com/elazarl/goproxy/regretable"
)

var RespIsImage = ContentTypeIs("image/gif",
Expand Down
14 changes: 7 additions & 7 deletions proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,13 +666,13 @@ func TestGoproxyHijackConnect(t *testing.T) {
proxy := goproxy.NewProxyHttpServer()
proxy.OnRequest(goproxy.ReqHostIs(srv.Listener.Addr().String())).
HijackConnect(func(req *http.Request, client net.Conn, ctx *goproxy.ProxyCtx) {
t.Logf("URL %+#v\nSTR %s", req.URL, req.URL.String())
resp, err := http.Get("http:" + req.URL.String() + "/bobo")
panicOnErr(err, "http.Get(CONNECT url)")
panicOnErr(resp.Write(client), "resp.Write(client)")
resp.Body.Close()
client.Close()
})
t.Logf("URL %+#v\nSTR %s", req.URL, req.URL.String())
resp, err := http.Get("http:" + req.URL.String() + "/bobo")
panicOnErr(err, "http.Get(CONNECT url)")
panicOnErr(resp.Write(client), "resp.Write(client)")
resp.Body.Close()
client.Close()
})
client, l := oneShotProxy(proxy, t)
defer l.Close()
proxyAddr := l.Listener.Addr().String()
Expand Down
6 changes: 3 additions & 3 deletions regretable/regretreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var defaultBufferSize = 500
// Same as RegretableReader, but allows closing the underlying reader
type RegretableReaderCloser struct {
RegretableReader
c io.Closer
c io.Closer
}

// Closes the underlying readCloser, you cannot regret after closing the stream
Expand Down Expand Up @@ -69,7 +69,7 @@ func (rb *RegretableReader) Forget() {

// initialize a RegretableReader with underlying reader r, whose buffer is size bytes long
func NewRegretableReaderSize(r io.Reader, size int) *RegretableReader {
return &RegretableReader{reader: r, buf: make([]byte, size) }
return &RegretableReader{reader: r, buf: make([]byte, size)}
}

// initialize a RegretableReader with underlying reader r
Expand All @@ -89,7 +89,7 @@ func (rb *RegretableReader) Read(p []byte) (n int, err error) {
}
n, err = rb.reader.Read(p)
bn := copy(rb.buf[rb.w:], p[:n])
rb.w, rb.r = rb.w + bn, rb.w + n
rb.w, rb.r = rb.w+bn, rb.w+n
if bn < n {
rb.overflow = true
}
Expand Down
6 changes: 3 additions & 3 deletions regretable/regretreader_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package regretable_test

import (
. "github.com/elazarl/goproxy/regretable"
"bytes"
. "github.com/elazarl/goproxy/regretable"
"io"
"io/ioutil"
"strings"
Expand Down Expand Up @@ -94,14 +94,14 @@ func TestRegretableFullRead(t *testing.T) {
}

func assertEqual(t *testing.T, expected, actual string) {
if expected!=actual {
if expected != actual {
t.Fatal("Expected", expected, "actual", actual)
}
}

func assertReadAll(t *testing.T, r io.Reader) string {
s, err := ioutil.ReadAll(r)
if err!=nil {
if err != nil {
t.Fatal("error when reading", err)
}
return string(s)
Expand Down
2 changes: 2 additions & 0 deletions transport/roundtripper.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package transport

import "net/http"

type RoundTripper interface {
// RoundTrip executes a single HTTP transaction, returning
// the Response for the request req. RoundTrip should not
Expand Down
24 changes: 12 additions & 12 deletions transport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// license that can be found in the LICENSE file.

// HTTP client implementation. See RFC 2616.
//
//
// This is the low-level Transport implementation of RoundTripper.
// The high-level interface is in client.go.

Expand All @@ -12,7 +12,6 @@
package transport

import (
"net/http"
"bufio"
"compress/gzip"
"crypto/tls"
Expand All @@ -23,6 +22,7 @@ import (
"io/ioutil"
"log"
"net"
"net/http"
"net/url"
"os"
"strings"
Expand Down Expand Up @@ -114,8 +114,8 @@ func ProxyURL(fixedURL *url.URL) func(*http.Request) (*url.URL, error) {
// transportRequest is a wrapper around a *Request that adds
// optional extra headers to write.
type transportRequest struct {
*http.Request // original request, not to be mutated
extra http.Header // extra headers to write, or nil
*http.Request // original request, not to be mutated
extra http.Header // extra headers to write, or nil
}

func (tr *transportRequest) extraHeaders() http.Header {
Expand All @@ -126,10 +126,10 @@ func (tr *transportRequest) extraHeaders() http.Header {
}

type RoundTripDetails struct {
Host string
Host string
TCPAddr *net.TCPAddr
IsProxy bool
Error error
Error error
}

func (t *Transport) DetailedRoundTrip(req *http.Request) (details *RoundTripDetails, resp *http.Response, err error) {
Expand Down Expand Up @@ -311,15 +311,15 @@ func (t *Transport) getIdleConn(cm *connectMethod) (pconn *persistConn) {
func (t *Transport) dial(network, addr string) (c net.Conn, raddr string, ip *net.TCPAddr, err error) {
if t.Dial != nil {
ip, err = net.ResolveTCPAddr("tcp", addr)
if err!=nil {
if err != nil {
return
}
c, err = t.Dial(network, addr)
raddr = addr
return
}
addri, err := net.ResolveTCPAddr("tcp", addr)
if err!=nil {
if err != nil {
return
}
c, err = net.DialTCP("tcp", nil, addri)
Expand Down Expand Up @@ -352,8 +352,8 @@ func (t *Transport) getConn(cm *connectMethod) (*persistConn, error) {
cacheKey: cm.String(),
conn: conn,
reqch: make(chan requestAndChan, 50),
host: raddr,
ip: ip,
host: raddr,
ip: ip,
}

switch {
Expand Down Expand Up @@ -526,7 +526,7 @@ type persistConn struct {
broken bool // an error has happened on this connection; marked broken so it's not reused.

host string
ip *net.TCPAddr
ip *net.TCPAddr
}

func (pc *persistConn) isBroken() bool {
Expand Down Expand Up @@ -664,7 +664,7 @@ func (pc *persistConn) roundTrip(req *transportRequest) (resp *http.Response, er
// requested it.
requestedGzip := false
if !pc.t.DisableCompression && req.Header.Get("Accept-Encoding") == "" {
// Request gzip only, not deflate. Deflate is ambiguous and
// Request gzip only, not deflate. Deflate is ambiguous and
// not as universally supported anyway.
// See: http://www.gzip.org/zlib/zlib_faq.html#faq38
requestedGzip = true
Expand Down

0 comments on commit 947c36d

Please sign in to comment.