add support for specifying output image format

For now, the options are "jpeg" and "png".  Gif is a little harder to
support because of the way we use the image/gif package to handle
animated gifs. I have also have trouble imagining someone wanting to use
gif over png. But if the need really exists, we can address it when it
comes up.

Fixes #89
This commit is contained in:
Will Norris 2017-06-01 07:51:14 -07:00
parent 2937bf84f6
commit b9cc9df4b6
4 changed files with 37 additions and 8 deletions

View file

@ -306,7 +306,10 @@ func (t *TransformingTransport) RoundTrip(req *http.Request) (*http.Response, er
// replay response with transformed image and updated content length
buf := new(bytes.Buffer)
fmt.Fprintf(buf, "%s %s\n", resp.Proto, resp.Status)
resp.Header.WriteSubset(buf, map[string]bool{"Content-Length": true})
resp.Header.WriteSubset(buf, map[string]bool{
"Content-Length": true,
"Content-Type": opt.Format != "",
})
fmt.Fprintf(buf, "Content-Length: %d\n\n", len(img))
buf.Write(img)