@@ -190,6 +190,7 @@ func (s *SouinBaseHandler) Store(
190
190
rq * http.Request ,
191
191
requestCc * cacheobject.RequestCacheDirectives ,
192
192
cachedKey string ,
193
+ uri string ,
193
194
) error {
194
195
statusCode := customWriter .GetStatusCode ()
195
196
if ! isCacheableCode (statusCode ) {
@@ -341,6 +342,7 @@ func (s *SouinBaseHandler) Store(
341
342
variedKey ,
342
343
) == nil {
343
344
s .Configuration .GetLogger ().Sugar ().Debugf ("Stored the key %s in the %s provider" , variedKey , currentStorer .Name ())
345
+ res .Request = rq
344
346
} else {
345
347
mu .Lock ()
346
348
fails = append (fails , fmt .Sprintf ("; detail=%s-INSERTION-ERROR" , currentStorer .Name ()))
@@ -351,9 +353,9 @@ func (s *SouinBaseHandler) Store(
351
353
352
354
wg .Wait ()
353
355
if len (fails ) < s .storersLen {
354
- go func (rs http.Response , key string ) {
355
- _ = s .SurrogateKeyStorer .Store (& rs , key )
356
- }(res , variedKey )
356
+ go func (rs http.Response , key string , basekey string ) {
357
+ _ = s .SurrogateKeyStorer .Store (& rs , key , uri , basekey )
358
+ }(res , variedKey , cachedKey )
357
359
status += "; stored"
358
360
}
359
361
@@ -387,6 +389,7 @@ func (s *SouinBaseHandler) Upstream(
387
389
next handlerFunc ,
388
390
requestCc * cacheobject.RequestCacheDirectives ,
389
391
cachedKey string ,
392
+ uri string ,
390
393
) error {
391
394
s .Configuration .GetLogger ().Sugar ().Debug ("Request the upstream server" )
392
395
prometheus .Increment (prometheus .RequestCounter )
@@ -434,7 +437,7 @@ func (s *SouinBaseHandler) Upstream(
434
437
customWriter .Header ().Set (headerName , s .DefaultMatchedUrl .DefaultCacheControl )
435
438
}
436
439
437
- err := s .Store (customWriter , rq , requestCc , cachedKey )
440
+ err := s .Store (customWriter , rq , requestCc , cachedKey , uri )
438
441
defer customWriter .Buf .Reset ()
439
442
440
443
return singleflightValue {
@@ -458,7 +461,7 @@ func (s *SouinBaseHandler) Upstream(
458
461
for _ , vh := range variedHeaders {
459
462
if rq .Header .Get (vh ) != sfWriter .requestHeaders .Get (vh ) {
460
463
// cachedKey += rfc.GetVariedCacheKey(rq, variedHeaders)
461
- return s .Upstream (customWriter , rq , next , requestCc , cachedKey )
464
+ return s .Upstream (customWriter , rq , next , requestCc , cachedKey , uri )
462
465
}
463
466
}
464
467
}
@@ -474,7 +477,7 @@ func (s *SouinBaseHandler) Upstream(
474
477
return nil
475
478
}
476
479
477
- func (s * SouinBaseHandler ) Revalidate (validator * core.Revalidator , next handlerFunc , customWriter * CustomWriter , rq * http.Request , requestCc * cacheobject.RequestCacheDirectives , cachedKey string ) error {
480
+ func (s * SouinBaseHandler ) Revalidate (validator * core.Revalidator , next handlerFunc , customWriter * CustomWriter , rq * http.Request , requestCc * cacheobject.RequestCacheDirectives , cachedKey string , uri string ) error {
478
481
s .Configuration .GetLogger ().Sugar ().Debug ("Revalidate the request with the upstream server" )
479
482
prometheus .Increment (prometheus .RequestRevalidationCounter )
480
483
@@ -496,7 +499,7 @@ func (s *SouinBaseHandler) Revalidate(validator *core.Revalidator, next handlerF
496
499
}
497
500
498
501
if statusCode != http .StatusNotModified {
499
- err = s .Store (customWriter , rq , requestCc , cachedKey )
502
+ err = s .Store (customWriter , rq , requestCc , cachedKey , uri )
500
503
}
501
504
}
502
505
@@ -616,6 +619,8 @@ func (s *SouinBaseHandler) ServeHTTP(rw http.ResponseWriter, rq *http.Request, n
616
619
}
617
620
cachedKey := req .Context ().Value (context .Key ).(string )
618
621
622
+ // Need to copy URL path before calling next because it can alter the URI
623
+ uri := req .URL .Path
619
624
bufPool := s .bufPool .Get ().(* bytes.Buffer )
620
625
bufPool .Reset ()
621
626
defer s .bufPool .Put (bufPool )
@@ -669,14 +674,14 @@ func (s *SouinBaseHandler) ServeHTTP(rw http.ResponseWriter, rq *http.Request, n
669
674
}
670
675
671
676
if validator .NeedRevalidation {
672
- err := s .Revalidate (validator , next , customWriter , req , requestCc , cachedKey )
677
+ err := s .Revalidate (validator , next , customWriter , req , requestCc , cachedKey , uri )
673
678
_ , _ = customWriter .Send ()
674
679
675
680
return err
676
681
}
677
682
if resCc , _ := cacheobject .ParseResponseCacheControl (rfc .HeaderAllCommaSepValuesString (response .Header , headerName )); resCc .NoCachePresent {
678
683
prometheus .Increment (prometheus .NoCachedResponseCounter )
679
- err := s .Revalidate (validator , next , customWriter , req , requestCc , cachedKey )
684
+ err := s .Revalidate (validator , next , customWriter , req , requestCc , cachedKey , uri )
680
685
_ , _ = customWriter .Send ()
681
686
682
687
return err
@@ -711,9 +716,9 @@ func (s *SouinBaseHandler) ServeHTTP(rw http.ResponseWriter, rq *http.Request, n
711
716
_ , _ = io .Copy (customWriter .Buf , response .Body )
712
717
_ , err := customWriter .Send ()
713
718
customWriter = NewCustomWriter (req , rw , bufPool )
714
- go func (v * core.Revalidator , goCw * CustomWriter , goRq * http.Request , goNext func (http.ResponseWriter , * http.Request ) error , goCc * cacheobject.RequestCacheDirectives , goCk string ) {
715
- _ = s .Revalidate (v , goNext , goCw , goRq , goCc , goCk )
716
- }(validator , customWriter , req , next , requestCc , cachedKey )
719
+ go func (v * core.Revalidator , goCw * CustomWriter , goRq * http.Request , goNext func (http.ResponseWriter , * http.Request ) error , goCc * cacheobject.RequestCacheDirectives , goCk string , goUri string ) {
720
+ _ = s .Revalidate (v , goNext , goCw , goRq , goCc , goCk , goUri )
721
+ }(validator , customWriter , req , next , requestCc , cachedKey , uri )
717
722
buf := s .bufPool .Get ().(* bytes.Buffer )
718
723
buf .Reset ()
719
724
defer s .bufPool .Put (buf )
@@ -723,7 +728,7 @@ func (s *SouinBaseHandler) ServeHTTP(rw http.ResponseWriter, rq *http.Request, n
723
728
724
729
if responseCc .MustRevalidate || responseCc .NoCachePresent || validator .NeedRevalidation {
725
730
req .Header ["If-None-Match" ] = append (req .Header ["If-None-Match" ], validator .ResponseETag )
726
- err := s .Revalidate (validator , next , customWriter , req , requestCc , cachedKey )
731
+ err := s .Revalidate (validator , next , customWriter , req , requestCc , cachedKey , uri )
727
732
statusCode := customWriter .GetStatusCode ()
728
733
if err != nil {
729
734
if responseCc .StaleIfError > - 1 || requestCc .StaleIfError > 0 {
@@ -785,7 +790,7 @@ func (s *SouinBaseHandler) ServeHTTP(rw http.ResponseWriter, rq *http.Request, n
785
790
errorCacheCh := make (chan error )
786
791
go func (vr * http.Request , cw * CustomWriter ) {
787
792
prometheus .Increment (prometheus .NoCachedResponseCounter )
788
- errorCacheCh <- s .Upstream (cw , vr , next , requestCc , cachedKey )
793
+ errorCacheCh <- s .Upstream (cw , vr , next , requestCc , cachedKey , uri )
789
794
}(req , customWriter )
790
795
791
796
select {
0 commit comments