@@ -208,7 +208,7 @@ func (app *Imagor) ServeHTTP(w http.ResponseWriter, r *http.Request) {
208
208
return
209
209
}
210
210
app .setResponseHeaders (w , r , blob , p )
211
- if checkStatNotModified (w , r , blob .Stat ) {
211
+ if blob != nil && checkStatNotModified (w , r , blob .Stat ) {
212
212
w .WriteHeader (http .StatusNotModified )
213
213
return
214
214
}
@@ -779,6 +779,10 @@ func (app *Imagor) suppress(
779
779
780
780
// setResponseHeaders sets common response headers for blob responses
781
781
func (app * Imagor ) setResponseHeaders (w http.ResponseWriter , r * http.Request , blob * Blob , p imagorpath.Params ) {
782
+ if blob == nil {
783
+ w .Header ().Set ("Content-Type" , "application/octet-stream" )
784
+ return
785
+ }
782
786
w .Header ().Set ("Content-Type" , blob .ContentType ())
783
787
w .Header ().Set ("Content-Disposition" , getContentDisposition (p , blob ))
784
788
setCacheHeaders (w , r , getTtl (p , app .CacheHeaderTTL ), app .CacheHeaderSWR )
@@ -966,9 +970,11 @@ func getContentDisposition(p imagorpath.Params, blob *Blob) string {
966
970
_ , filename = filepath .Split (p .Image )
967
971
}
968
972
filename = strings .ReplaceAll (filename , `"` , "%22" )
969
- if ext := getExtension (blob .BlobType ()); ext != "" &&
970
- ! (ext == ".jpg" && strings .HasSuffix (filename , ".jpeg" )) {
971
- filename = strings .TrimSuffix (filename , ext ) + ext
973
+ if blob != nil {
974
+ if ext := getExtension (blob .BlobType ()); ext != "" &&
975
+ ! (ext == ".jpg" && strings .HasSuffix (filename , ".jpeg" )) {
976
+ filename = strings .TrimSuffix (filename , ext ) + ext
977
+ }
972
978
}
973
979
return fmt .Sprintf (`attachment; filename="%s"` , filename )
974
980
}
0 commit comments