Skip to content

Commit f9cf8e5

Browse files
mvdantombergan
authored andcommitted
net/http: various small cleanups
* Remove an unnecessary type conversion * Make golint happier about consistent receiver names * Make golint happier about a foo_bar var name Change-Id: I5223808109f6f8b69ed4be76de82faf2478c6a2e Reviewed-on: https://go-review.googlesource.com/54530 Run-TryBot: Daniel Martí <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Tom Bergan <[email protected]>
1 parent cc4aac2 commit f9cf8e5

File tree

4 files changed

+22
-23
lines changed

4 files changed

+22
-23
lines changed

src/net/http/fs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ func scanETag(s string) (etag string, remain string) {
317317
// Character values allowed in ETags.
318318
case c == 0x21 || c >= 0x23 && c <= 0x7E || c >= 0x80:
319319
case c == '"':
320-
return string(s[:i+1]), s[i+1:]
320+
return s[:i+1], s[i+1:]
321321
default:
322322
return "", ""
323323
}

src/net/http/request.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,8 @@ var errMissingHost = errors.New("http: Request.Write on Request with no Host or
490490

491491
// extraHeaders may be nil
492492
// waitForContinue may be nil
493-
func (req *Request) write(w io.Writer, usingProxy bool, extraHeaders Header, waitForContinue func() bool) (err error) {
494-
trace := httptrace.ContextClientTrace(req.Context())
493+
func (r *Request) write(w io.Writer, usingProxy bool, extraHeaders Header, waitForContinue func() bool) (err error) {
494+
trace := httptrace.ContextClientTrace(r.Context())
495495
if trace != nil && trace.WroteRequest != nil {
496496
defer func() {
497497
trace.WroteRequest(httptrace.WroteRequestInfo{
@@ -504,23 +504,23 @@ func (req *Request) write(w io.Writer, usingProxy bool, extraHeaders Header, wai
504504
// is not given, use the host from the request URL.
505505
//
506506
// Clean the host, in case it arrives with unexpected stuff in it.
507-
host := cleanHost(req.Host)
507+
host := cleanHost(r.Host)
508508
if host == "" {
509-
if req.URL == nil {
509+
if r.URL == nil {
510510
return errMissingHost
511511
}
512-
host = cleanHost(req.URL.Host)
512+
host = cleanHost(r.URL.Host)
513513
}
514514

515515
// According to RFC 6874, an HTTP client, proxy, or other
516516
// intermediary must remove any IPv6 zone identifier attached
517517
// to an outgoing URI.
518518
host = removeZone(host)
519519

520-
ruri := req.URL.RequestURI()
521-
if usingProxy && req.URL.Scheme != "" && req.URL.Opaque == "" {
522-
ruri = req.URL.Scheme + "://" + host + ruri
523-
} else if req.Method == "CONNECT" && req.URL.Path == "" {
520+
ruri := r.URL.RequestURI()
521+
if usingProxy && r.URL.Scheme != "" && r.URL.Opaque == "" {
522+
ruri = r.URL.Scheme + "://" + host + ruri
523+
} else if r.Method == "CONNECT" && r.URL.Path == "" {
524524
// CONNECT requests normally give just the host and port, not a full URL.
525525
ruri = host
526526
}
@@ -536,7 +536,7 @@ func (req *Request) write(w io.Writer, usingProxy bool, extraHeaders Header, wai
536536
w = bw
537537
}
538538

539-
_, err = fmt.Fprintf(w, "%s %s HTTP/1.1\r\n", valueOrDefault(req.Method, "GET"), ruri)
539+
_, err = fmt.Fprintf(w, "%s %s HTTP/1.1\r\n", valueOrDefault(r.Method, "GET"), ruri)
540540
if err != nil {
541541
return err
542542
}
@@ -550,8 +550,8 @@ func (req *Request) write(w io.Writer, usingProxy bool, extraHeaders Header, wai
550550
// Use the defaultUserAgent unless the Header contains one, which
551551
// may be blank to not send the header.
552552
userAgent := defaultUserAgent
553-
if _, ok := req.Header["User-Agent"]; ok {
554-
userAgent = req.Header.Get("User-Agent")
553+
if _, ok := r.Header["User-Agent"]; ok {
554+
userAgent = r.Header.Get("User-Agent")
555555
}
556556
if userAgent != "" {
557557
_, err = fmt.Fprintf(w, "User-Agent: %s\r\n", userAgent)
@@ -561,7 +561,7 @@ func (req *Request) write(w io.Writer, usingProxy bool, extraHeaders Header, wai
561561
}
562562

563563
// Process Body,ContentLength,Close,Trailer
564-
tw, err := newTransferWriter(req)
564+
tw, err := newTransferWriter(r)
565565
if err != nil {
566566
return err
567567
}
@@ -570,7 +570,7 @@ func (req *Request) write(w io.Writer, usingProxy bool, extraHeaders Header, wai
570570
return err
571571
}
572572

573-
err = req.Header.WriteSubset(w, reqWriteExcludeHeader)
573+
err = r.Header.WriteSubset(w, reqWriteExcludeHeader)
574574
if err != nil {
575575
return err
576576
}
@@ -603,7 +603,7 @@ func (req *Request) write(w io.Writer, usingProxy bool, extraHeaders Header, wai
603603
trace.Wait100Continue()
604604
}
605605
if !waitForContinue() {
606-
req.closeBody()
606+
r.closeBody()
607607
return nil
608608
}
609609
}

src/net/http/transfer.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,9 +663,8 @@ func fixLength(isResponse bool, status int, requestMethod string, header Header,
663663
return -1, err
664664
}
665665
return n, nil
666-
} else {
667-
header.Del("Content-Length")
668666
}
667+
header.Del("Content-Length")
669668

670669
if isRequest {
671670
// RFC 2616 neither explicitly permits nor forbids an

src/net/http/transport.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,8 +1224,8 @@ func useProxy(addr string) bool {
12241224
}
12251225
}
12261226

1227-
no_proxy := noProxyEnv.Get()
1228-
if no_proxy == "*" {
1227+
noProxy := noProxyEnv.Get()
1228+
if noProxy == "*" {
12291229
return false
12301230
}
12311231

@@ -1234,7 +1234,7 @@ func useProxy(addr string) bool {
12341234
addr = addr[:strings.LastIndex(addr, ":")]
12351235
}
12361236

1237-
for _, p := range strings.Split(no_proxy, ",") {
1237+
for _, p := range strings.Split(noProxy, ",") {
12381238
p = strings.ToLower(strings.TrimSpace(p))
12391239
if len(p) == 0 {
12401240
continue
@@ -2021,8 +2021,8 @@ func (pc *persistConn) roundTrip(req *transportRequest) (resp *Response, err err
20212021
// a t.Logf func. See export_test.go's Request.WithT method.
20222022
type tLogKey struct{}
20232023

2024-
func (r *transportRequest) logf(format string, args ...interface{}) {
2025-
if logf, ok := r.Request.Context().Value(tLogKey{}).(func(string, ...interface{})); ok {
2024+
func (tr *transportRequest) logf(format string, args ...interface{}) {
2025+
if logf, ok := tr.Request.Context().Value(tLogKey{}).(func(string, ...interface{})); ok {
20262026
logf(time.Now().Format(time.RFC3339Nano)+": "+format, args...)
20272027
}
20282028
}

0 commit comments

Comments
 (0)