Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1425)

Unified Diff: src/pkg/http/transport.go

Issue 4893043: code review 4893043: url: new package (Closed)
Patch Set: diff -r a8d309fd526f https://go.googlecode.com/hg/ Created 13 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/pkg/http/server.go ('k') | src/pkg/http/transport_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pkg/http/transport.go
===================================================================
--- a/src/pkg/http/transport.go
+++ b/src/pkg/http/transport.go
@@ -17,6 +17,7 @@
"os"
"strings"
"sync"
+ "url"
)
// DefaultTransport is the default implementation of Transport and is
@@ -46,7 +47,7 @@
// Request. If the function returns a non-nil error, the
// request is aborted with the provided error.
// If Proxy is nil or returns a nil *URL, no proxy is used.
- Proxy func(*Request) (*URL, os.Error)
+ Proxy func(*Request) (*url.URL, os.Error)
// Dial specifies the dial function for creating TCP
// connections.
@@ -66,7 +67,7 @@
// given request, as indicated by the environment variables
// $HTTP_PROXY and $NO_PROXY (or $http_proxy and $no_proxy).
// Either URL or an error is returned.
-func ProxyFromEnvironment(req *Request) (*URL, os.Error) {
+func ProxyFromEnvironment(req *Request) (*url.URL, os.Error) {
proxy := getenvEitherCase("HTTP_PROXY")
if proxy == "" {
return nil, nil
@@ -74,12 +75,12 @@
if !useProxy(canonicalAddr(req.URL)) {
return nil, nil
}
- proxyURL, err := ParseRequestURL(proxy)
+ proxyURL, err := url.ParseRequest(proxy)
if err != nil {
return nil, os.NewError("invalid proxy address")
}
if proxyURL.Host == "" {
- proxyURL, err = ParseRequestURL("http://" + proxy)
+ proxyURL, err = url.ParseRequest("http://" + proxy)
if err != nil {
return nil, os.NewError("invalid proxy address")
}
@@ -89,16 +90,16 @@
// ProxyURL returns a proxy function (for use in a Transport)
// that always returns the same URL.
-func ProxyURL(url *URL) func(*Request) (*URL, os.Error) {
- return func(*Request) (*URL, os.Error) {
- return url, nil
+func ProxyURL(fixedURL *url.URL) func(*Request) (*url.URL, os.Error) {
+ return func(*Request) (*url.URL, os.Error) {
+ return fixedURL, nil
}
}
// RoundTrip implements the RoundTripper interface.
func (t *Transport) RoundTrip(req *Request) (resp *Response, err os.Error) {
if req.URL == nil {
- if req.URL, err = ParseURL(req.RawURL); err != nil {
+ if req.URL, err = url.Parse(req.RawURL); err != nil {
return
}
}
@@ -413,9 +414,9 @@
// Note: no support to https to the proxy yet.
//
type connectMethod struct {
- proxyURL *URL // "" for no proxy, else full proxy URL
- targetScheme string // "http" or "https"
- targetAddr string // Not used if proxy + http targetScheme (4th example in table)
+ proxyURL *url.URL // nil for no proxy, else full proxy URL
+ targetScheme string // "http" or "https"
+ targetAddr string // Not used if proxy + http targetScheme (4th example in table)
}
func (ck *connectMethod) String() string {
@@ -642,7 +643,7 @@
}
// canonicalAddr returns url.Host but always with a ":port" suffix
-func canonicalAddr(url *URL) string {
+func canonicalAddr(url *url.URL) string {
addr := url.Host
if !hasPort(addr) {
return addr + ":" + portMap[url.Scheme]
« no previous file with comments | « src/pkg/http/server.go ('k') | src/pkg/http/transport_test.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b