Modifying http.Request in http/client.go?

421 views
Skip to first unread message

Peter Bourgon

unread,
Mar 6, 2010, 5:16:21 AM3/6/10
to golang-nuts
I need to submit a HTTP request with a request.Method and
request.Headers that I specify. I could do this no problem if
http/client.go's send() method was public. But, as it stands, the only
way I could figure out how to do it was to add a new method there:

func ArbitraryRequest(req Request, body io.Reader) (r *Response, err
os.Error) {
req.Body = nopCloser{body}
return send(&req)
}

Is there a better way, or should I submit my modification as a patch?

Michael Hoisie

unread,
Mar 6, 2010, 12:43:01 PM3/6/10
to golang-nuts
Check out http.ClientConn, it gets the job done . It should be
available in the past two releases.

This is a snippet using it: http://pastie.org/836335

- Mike

Peter Bourgon

unread,
Mar 6, 2010, 1:16:51 PM3/6/10
to golang-nuts
Thanks for the heads-up. It's quite a bit more... verbose than what I
was working with, but I'll go with it for now. I think there's still
room for a function like mine; if any of the authors agrees just let
me know.

Michael Hoisie

unread,
Mar 6, 2010, 4:08:31 PM3/6/10
to golang-nuts
I've been pushing for that exact method for a while (even submitted a
patch) but haven't had any luck. http.ClientConn is a step forward,
but it is awkward to use.

I think that Russ and Petarm are planning to build a richer interface
on top of http.ClientConn.

- Mike

P.S I might rewrite http://github.com/hoisie/httplib.go to use
http.ClientConn .

Peter Bourgon

unread,
Mar 8, 2010, 4:06:18 AM3/8/10
to golang-nuts
Ah, I see this has been extensively discussed... forgive my rehash. +1
to everything mentioned below:

http://groups.google.com/group/golang-nuts/browse_thread/thread/c381b81c291bb527
http://code.google.com/p/go/issues/detail?id=155

Reply all
Reply to author
Forward
0 new messages