<p dir="auto">I'd like to add a method to <code class="notranslate">os/exec.Cmd</code> to ease setting environment variables on commands before they're run.</p>
<p dir="auto">Manipulating <code class="notranslate">Env []string</code> lists is tedious and error-prone, especially considering potential duplicates. (since programs would others choose either the first or last occurrence, unpredictably)</p>
<p dir="auto">The proposed <code class="notranslate">Cmd.SetEnv(key, value string)</code> method would be documented as removing duplicates.</p>
<p dir="auto">On Windows, environment variables are case-insensitive, so the method on Windows should de-dup case insensitively.</p>
<p dir="auto">This method would replace a handful of copies of <code class="notranslate">func mergeEnvLists</code> that exist in various forms around the standard library, tests, and x/* repos.</p>
<p dir="auto">/cc <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/ianlancetaylor/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/ianlancetaylor">@ianlancetaylor</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/adg/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/adg">@adg</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/rsc/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/rsc">@rsc</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/griesemer/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/griesemer">@griesemer</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/robpike/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/robpike">@robpike</a></p>
<pre class="notranslate">I am working in a severely bandwidth-limited environment and am trying to strip down the
http responses generated by net/http. I would like to prevent the Content-Type and
Connection headers from being inserted into the http response. (The Connection header
should be safe to remove at least for HTTP/1.0 requests.) It does not currently seem
possible.

I would ideally like this to remove the Content-Type and Connection headers (it
currently works for removing the Date header):

    header := resp.Header()
    header["Content-Type"] = nil
    header["Connection"] = nil


As a bonus bug:

    header["Content-Type"] = []string{""}

causes duplicate Content-Type headers in the response:

HTTP/1.0 200 OK
Content-Type: 
Content-Type: text/plain; charset=utf-8
Content-Length: 0
Connection: close


I would be happy to write a patch for this, if so desired.


Which version are you using?  (run 'go version')

1.1.1</pre>