// extraHeaders may be nil
// waitForContinue may be nil
-func (req *Request) write(w io.Writer, usingProxy bool, extraHeaders Header, waitForContinue func() bool) (err error) {
- trace := httptrace.ContextClientTrace(req.Context())
+func (r *Request) write(w io.Writer, usingProxy bool, extraHeaders Header, waitForContinue func() bool) (err error) {
+ trace := httptrace.ContextClientTrace(r.Context())
if trace != nil && trace.WroteRequest != nil {
defer func() {
trace.WroteRequest(httptrace.WroteRequestInfo{
// is not given, use the host from the request URL.
//
// Clean the host, in case it arrives with unexpected stuff in it.
- host := cleanHost(req.Host)
+ host := cleanHost(r.Host)
if host == "" {
- if req.URL == nil {
+ if r.URL == nil {
return errMissingHost
}
- host = cleanHost(req.URL.Host)
+ host = cleanHost(r.URL.Host)
}
// According to RFC 6874, an HTTP client, proxy, or other
// to an outgoing URI.
host = removeZone(host)
- ruri := req.URL.RequestURI()
- if usingProxy && req.URL.Scheme != "" && req.URL.Opaque == "" {
- ruri = req.URL.Scheme + "://" + host + ruri
- } else if req.Method == "CONNECT" && req.URL.Path == "" {
+ ruri := r.URL.RequestURI()
+ if usingProxy && r.URL.Scheme != "" && r.URL.Opaque == "" {
+ ruri = r.URL.Scheme + "://" + host + ruri
+ } else if r.Method == "CONNECT" && r.URL.Path == "" {
// CONNECT requests normally give just the host and port, not a full URL.
ruri = host
}
w = bw
}
- _, err = fmt.Fprintf(w, "%s %s HTTP/1.1\r\n", valueOrDefault(req.Method, "GET"), ruri)
+ _, err = fmt.Fprintf(w, "%s %s HTTP/1.1\r\n", valueOrDefault(r.Method, "GET"), ruri)
if err != nil {
return err
}
// Use the defaultUserAgent unless the Header contains one, which
// may be blank to not send the header.
userAgent := defaultUserAgent
- if _, ok := req.Header["User-Agent"]; ok {
- userAgent = req.Header.Get("User-Agent")
+ if _, ok := r.Header["User-Agent"]; ok {
+ userAgent = r.Header.Get("User-Agent")
}
if userAgent != "" {
_, err = fmt.Fprintf(w, "User-Agent: %s\r\n", userAgent)
}
// Process Body,ContentLength,Close,Trailer
- tw, err := newTransferWriter(req)
+ tw, err := newTransferWriter(r)
if err != nil {
return err
}
return err
}
- err = req.Header.WriteSubset(w, reqWriteExcludeHeader)
+ err = r.Header.WriteSubset(w, reqWriteExcludeHeader)
if err != nil {
return err
}
trace.Wait100Continue()
}
if !waitForContinue() {
- req.closeBody()
+ r.closeBody()
return nil
}
}
}
}
- no_proxy := noProxyEnv.Get()
- if no_proxy == "*" {
+ noProxy := noProxyEnv.Get()
+ if noProxy == "*" {
return false
}
addr = addr[:strings.LastIndex(addr, ":")]
}
- for _, p := range strings.Split(no_proxy, ",") {
+ for _, p := range strings.Split(noProxy, ",") {
p = strings.ToLower(strings.TrimSpace(p))
if len(p) == 0 {
continue
// a t.Logf func. See export_test.go's Request.WithT method.
type tLogKey struct{}
-func (r *transportRequest) logf(format string, args ...interface{}) {
- if logf, ok := r.Request.Context().Value(tLogKey{}).(func(string, ...interface{})); ok {
+func (tr *transportRequest) logf(format string, args ...interface{}) {
+ if logf, ok := tr.Request.Context().Value(tLogKey{}).(func(string, ...interface{})); ok {
logf(time.Now().Format(time.RFC3339Nano)+": "+format, args...)
}
}