Skip to content

net/http: docs imply DefaultTransport doesn't use keep-alive connections, but it does #4281

@gopherbot

Description

@gopherbot

by jacobsa@google.com:

I started a golang-nuts thread for this (http://goo.gl/D7Gvt) but never got a
response for my final question.

Calling `http.Get` or `http.Do` without changing any of the default settings
uses keep-alive connections; you can verify this by running the program Russ
posted in the thread I linked above. However, the docs say this:

> DefaultTransport is the default implementation of Transport and is 
> used by DefaultClient. It establishes a new network connection for 
> each call to Do [...]. 

This seems incorrect, unless I'm misreading it. Re-using a cached keep-alive
connection means that a new network connection is *not* established for each
call to `Do`, right?

The docs for the `Transport` type agree with the actual behavior, implying
that its zero value will use keep-alive connections (due to a zero value for
`MaxIdleConnsPerHost` implying `DefaultMaxIdleConnsPerHost`, which is two).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions