| // Copyright 2011 The Go Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| post = flag.String("post", "", "urlencoded form data to POST") |
| addr = flag.Bool("addr", false, "find open address and print to stdout") |
| wait = flag.Duration("wait_for_port", 0, "if non-zero, the amount of time to wait for the address to become available") |
| l, err := net.Listen("tcp", "127.0.0.1:0") |
| log.Fatal("no url supplied") |
| loopUntil := time.Now().Add(*wait) |
| b := strings.NewReader(*post) |
| r, err = http.Post(url, "application/x-www-form-urlencoded", b) |
| if err == nil || *wait == 0 || time.Now().After(loopUntil) { |
| time.Sleep(100 * time.Millisecond) |
| _, err = io.Copy(os.Stdout, r.Body) |