Skip to content

Instantly share code, notes, and snippets.

@Meyermagic
Created January 24, 2013 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Meyermagic/4626358 to your computer and use it in GitHub Desktop.
Save Meyermagic/4626358 to your computer and use it in GitHub Desktop.
package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
)
var url string = "http://repo.bukkit.org/index.html"
func main() {
flag.StringVar(&url, "url", url, "URL to test against")
flag.Parse()
resp, err := http.Get(url)
//defer resp.Body.Close()
if err != nil {
log.Fatal(err)
}
fmt.Printf("%#v\n", resp)
if resp.Request != nil {
fmt.Printf("%#v\n", resp.Request)
}
_, err = ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
}
@Meyermagic
Copy link
Author

Fails with "use of closed network connection" on:

  • http://217.19.223.2:20001
  • http://localhost:8080/_ah/admin/datastore (my local appengine development server)
  • http://repo.bukkit.org/index.html

and succeeds without error on all other domains I've tested, notably:

  • http://www.example.com
  • http://a.tiles.mapbox.com/v3/marker/pin-l-bicycle+94eeff.png

In all the "fail" URLs above, curl -v will report

* additional stuff not fine transfer.c:1037: 0 0
* HTTP 1.0, assume close after body

In the two notable "succeed" URLs above, curl -v will, in addition to the previous message, report

* HTTP/1.0 connection set to keep alive!
< Connection: Keep-Alive

The failure case, then, seems to be HTTP 1.0 servers that do not report Connection: Keep-Alive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment