This little piece of code shows three problems I have encountered (and solved, with varying levels of success) while using Go on App Engine.
 endpoint, e :=  url.Parse(streamType)
 if e != nil { return stream, t.New("Parsing for %s failed.", streamType) }
 //  endpoint.User = url.UserPassword(auth.Username, auth.Password)
 client.Transport  = &http.Transport {
  Proxy : func(req *http.Request) (*url.URL, error) {
   req.SetBasicAuth(auth.Username, auth.Password)
   return nil, nil
  },
 }
 if post {
  resp, e = client.PostForm(endpoint.String(), options)
 } else {
  endpoint.RawQuery = options.Encode()
  resp, e = client.Get(endpoint.String())
 }
 if e != nil { return stream, t.New("Could not fetch %s (%s): %v", endpoint, options.Encode(), e) }
While URL’s that contain auth information are valid—likeÂ
http://user:pass...@www.1st.ug/ for example—the parser in Go’sÂ
net/url package can’t handle them. (In fact, in the code, the logic for dealing with URLs that have auth information is there, but the parsing of them fails consistently miserably.) This is the case both in development and in production.
My work-around, as you can see, was first to try to set the User attribute of the URL object. But for POST requests, it is ignored. Since I will be dealing with POST requests (as well as GET), I chose the option below it. I created a fake proxy, whose only job was to enforce auth. It does it on the Request object, which is never exposed anywhere at any point by the API. The trick works.
Then another problem shows up, in that in development, the thing works flawlessly, but in production it consistently returns permission denied. This is provoked by the proxy—in that GAE doesn’t allow me to work the proxy, even though that restriction is not documented explicity. When I remove the proxy dance, it works.
I wonder how one can express Basic Authentication for a HTTP request without running afoul of the gae gopher.
(This discussion system allows me to start a discussion xor ask a question; I want to do both!)