Aias00 opened a new issue, #6505: URL: https://github.com/apache/shenyu/issues/6505
### Search before asking - [x] I had searched in the [issues](https://github.com/apache/shenyu/issues) and found no similar issues. ### Apache ShenYu Component shenyu-plugin ### What happened `CachePlugin` stores only the response body and content type: ```java cache.cacheData(CacheUtils.dataKey(this.exchange), bodyBytes, this.cacheRuleHandle.getTimeoutSeconds()).subscribeOn(Schedulers.boundedElastic()).subscribe(); cache.cacheContentType(CacheUtils.contentTypeKey(this.exchange), contentType, this.cacheRuleHandle.getTimeoutSeconds()); ``` On a cache hit it only restores those two values: ```java byte[] bytes = dataFlg.get().getT1(); byte[] contentTypeBytes = dataFlg.get().getT2(); cache.setContentType(exchange, contentTypeBytes); return exchange.getResponse().writeWith(Mono.just(exchange.getResponse().bufferFactory().wrap(bytes)) .doOnNext(data -> exchange.getResponse().getHeaders().setContentLength(data.readableByteCount()))); ``` The upstream HTTP status code and other response headers are not cached or replayed. This changes response semantics after the first request. For example: - an upstream `404`/`500` response body can be replayed as a default gateway `200` on cache hit; - a cached `302` loses the `Location` header; - `Set-Cookie`, `Cache-Control`, and other important headers are dropped on cache hit. ### Expected behavior A cached HTTP response should preserve the response semantics that ShenYu returned when the entry was stored. At minimum, the cache entry should include and restore the HTTP status code and relevant response headers, or the cache plugin should explicitly avoid caching responses whose status/headers cannot be safely replayed. ### How to reproduce 1. Enable the cache plugin for a route. 2. Let the upstream return a non-200 response, or a redirect response such as: ```text HTTP/1.1 302 Found Location: /new-location Content-Type: text/plain ``` 3. Send the first request so the cache entry is created. 4. Send the same request again. 5. The cache hit path returns only cached body/content-type and does not restore the original status or headers. ### Debug logs _No response_ ### Environment Current `master` branch. ### Are you willing to submit a PR? - [ ] Yes I am willing to submit a PR! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
