Skip to content

[BUG] Cache plugin loses response status and headers on cache hit #6505

Closed

Description

@Aias00

Search before asking

  • I had searched in the issues and found no similar issues.

Apache ShenYu Component

shenyu-plugin

What happened

CachePlugin stores only the response body and content type:

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:

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:
HTTP/1.1 302 Found
Location: /new-location
Content-Type: text/plain
  1. Send the first request so the cache entry is created.
  2. Send the same request again.
  3. 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!

Activity

  1. github-actions commented on Jul 31, 2026

    @github-actions
    Contributor

    👋 Hello @yuluo-yx

    A new issue has been opened by @Aias00:

    Please review when you have time. Thank you! 🙏

  2. Aias00 commented on Aug 2, 2026

    @Aias00
    ContributorAuthor

    Cross-link: related to #6506 — both are CachePlugin correctness defects. This issue is about the cache entry scope (status code & response headers lost on cache hit, CachePlugin.java:139-150 stores only body+contentType), while #6506 is about the cache key (ignores HTTP method & body, CacheUtils.java:45-49). Worth fixing together in one CachePlugin pass.

  3. added a commit that references this issue on Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions