Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ func imageHandler(w http.ResponseWriter, r *http.Request, buf []byte, operation
// Expose Content-Length response header
w.Header().Set("Content-Length", strconv.Itoa(len(image.Body)))
w.Header().Set("Content-Type", image.Mime)
if image.Mime != "application/json" && o.ReturnSize {
meta, err := bimg.Metadata(image.Body)
if err == nil {
w.Header().Set("Image-Width", strconv.Itoa(meta.Size.Width))
w.Header().Set("Image-Height", strconv.Itoa(meta.Size.Height))
}
}
if vary != "" {
w.Header().Set("Vary", vary)
}
Expand Down
3 changes: 3 additions & 0 deletions imaginary.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var (
aMRelease = flag.Int("mrelease", 30, "OS memory release interval in seconds")
aCpus = flag.Int("cpus", runtime.GOMAXPROCS(-1), "Number of cpu cores to use")
aLogLevel = flag.String("log-level", "info", "Define log level for http-server. E.g: info,warning,error")
aReturnSize = flag.Bool("return-size", false, "Return the image size in the HTTP headers")
)

const usage = `imaginary %s
Expand Down Expand Up @@ -106,6 +107,7 @@ Options:
(default for current machine is %d cores)
-log-level Set log level for http-server. E.g: info,warning,error [default: info].
Or can use the environment variable GOLANG_LOG=info.
-return-size Return the image size with X-Width and X-Height HTTP header. [default: disabled].
`

type URLSignature struct {
Expand Down Expand Up @@ -157,6 +159,7 @@ func main() {
AllowedOrigins: parseOrigins(*aAllowedOrigins),
MaxAllowedSize: *aMaxAllowedSize,
LogLevel: getLogLevel(*aLogLevel),
ReturnSize: *aReturnSize,
}

// Show warning if gzip flag is passed
Expand Down
1 change: 1 addition & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type ServerOptions struct {
Endpoints Endpoints
AllowedOrigins []*url.URL
LogLevel string
ReturnSize bool
}

// Endpoints represents a list of endpoint names to disable.
Expand Down