mirror of
https://github.com/golang/go
synced 2024-11-18 22:04:43 -07:00
05a1b7ec41
This CL: -- removes Response.RequestMethod string -- adds Response.Request *Request -- removes the finalURL result parameter from client.Get() -- adds a gofix rule for callers of http.Get which assign the final url to the blank identifier; warning otherwise Caller who did: res, finalURL, err := http.Get(...) now need to do: res, err := http.Get(...) if err != nil { ... } finalURL := res.Request.URL.String() R=rsc CC=golang-dev https://golang.org/cl/4535056
51 lines
809 B
Go
51 lines
809 B
Go
package main
|
|
|
|
import (
|
|
"http"
|
|
"flag"
|
|
"fmt"
|
|
"io"
|
|
"log"
|
|
"net"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
var (
|
|
post = flag.String("post", "", "urlencoded form data to POST")
|
|
addr = flag.Bool("addr", false, "find open address and print to stdout")
|
|
)
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
if *addr {
|
|
l, err := net.Listen("tcp", "127.0.0.1:0")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer l.Close()
|
|
fmt.Print(l.Addr())
|
|
return
|
|
}
|
|
url := flag.Arg(0)
|
|
if url == "" {
|
|
log.Fatal("no url supplied")
|
|
}
|
|
var r *http.Response
|
|
var err os.Error
|
|
if *post != "" {
|
|
b := strings.NewReader(*post)
|
|
r, err = http.Post(url, "application/x-www-form-urlencoded", b)
|
|
} else {
|
|
r, err = http.Get(url)
|
|
}
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer r.Body.Close()
|
|
_, err = io.Copy(os.Stdout, r.Body)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|