@@ -425,6 +425,15 @@ func (req *Request) Send(ctx context.Context, backend string) (*Response, error)
425425 }
426426 }
427427
428+ if req .ImageOptimizerOptions != nil {
429+ response , err := req .sendToImageOpto (ctx , backend )
430+ if err != nil {
431+ return nil , fmt .Errorf ("send to image optimizer: %w" , err )
432+ }
433+
434+ return response , nil
435+ }
436+
428437 if ok , err := req .shouldUseGuestCaching (); err != nil {
429438 // can't determine if we should use guest cache or host cache
430439 return nil , err
@@ -541,31 +550,31 @@ func pendingToABIResponse(ctx context.Context, errc chan error, abiPending *fast
541550 }
542551}
543552
544- var guestCacheSWRPending sync.WaitGroup
553+ func (req * Request ) sendToImageOpto (ctx context.Context , backend string ) (* Response , error ) {
554+ // Send this request through the Image Optimizer infrastructure
555+ query , err := req .ImageOptimizerOptions .QueryString ()
556+ if err != nil {
557+ return nil , err
558+ }
545559
546- func (req * Request ) sendWithGuestCache (ctx context.Context , backend string ) (* Response , error ) {
547- // use guest cache
560+ abiResp , abiBody , err := req .abi .req .SendToImageOpto (req .abi .body , backend , query )
561+ if err != nil {
562+ return nil , err
548563
549- if req .ImageOptimizerOptions != nil {
550- // Send this request through the Image Optimizer infrastructure
551- query , err := req .ImageOptimizerOptions .QueryString ()
552- if err != nil {
553- return nil , err
554- }
564+ }
555565
556- abiResp , abiBody , err := req .abi .req .SendToImageOpto (req .abi .body , backend , query )
557- if err != nil {
558- return nil , err
566+ resp , err := newResponse (req , backend , abiResp , abiBody )
567+ if err != nil {
568+ return nil , fmt .Errorf ("construct response: %w" , err )
569+ }
559570
560- }
571+ return resp , nil
572+ }
561573
562- resp , err := newResponse (req , backend , abiResp , abiBody )
563- if err != nil {
564- return nil , fmt .Errorf ("construct response: %w" , err )
565- }
574+ var guestCacheSWRPending sync.WaitGroup
566575
567- return resp , nil
568- }
576+ func ( req * Request ) sendWithGuestCache ( ctx context. Context , backend string ) ( * Response , error ) {
577+ // use guest cache
569578
570579 if ok , err := fastly .HTTPCacheIsRequestCacheable (req .abi .req ); err != nil {
571580 return nil , fmt .Errorf ("request not cacheable: %v" , err )
@@ -803,6 +812,11 @@ func (req *Request) shouldUseGuestCaching() (bool, error) {
803812 return false , nil
804813 }
805814
815+ if req .ImageOptimizerOptions != nil {
816+ // request should go through imageopto
817+ return false , nil
818+ }
819+
806820 mustUseHostCaching , err := req .mustUseHostCaching ()
807821 // check for hostcall unsupported error
808822 if err != nil {
0 commit comments