From c90fe543391c483182d284eb10f79f60b38c5637 Mon Sep 17 00:00:00 2001 From: Zengyi Wang Date: Wed, 14 Aug 2024 20:56:05 +0800 Subject: [PATCH] fix batch 4 --- .../java/io/vertx/httpproxy/impl/CachingFilter.java | 11 +++++++++-- src/main/java/io/vertx/httpproxy/spi/cache/Cache.java | 2 +- .../java/io/vertx/httpproxy/spi/cache/Resource.java | 7 ------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/io/vertx/httpproxy/impl/CachingFilter.java b/src/main/java/io/vertx/httpproxy/impl/CachingFilter.java index edec8d5..c871476 100644 --- a/src/main/java/io/vertx/httpproxy/impl/CachingFilter.java +++ b/src/main/java/io/vertx/httpproxy/impl/CachingFilter.java @@ -42,7 +42,7 @@ private Future sendAndTryCacheProxyResponse(ProxyContext context) { if (cached != null && response.getStatusCode() == 304) { // Warning: this relies on the fact that HttpServerRequest will not send a body for HEAD response.release(); - cached.init(response); + fillResponseFromResource(response, cached); return context.sendResponse(); } @@ -138,9 +138,16 @@ private Future tryHandleProxyRequestFromCache(ProxyContext contex } proxyRequest.release(); ProxyResponse proxyResponse = proxyRequest.response(); - resource.init(proxyResponse); + fillResponseFromResource(proxyResponse, resource); return Future.succeededFuture(proxyResponse); }); } + + public void fillResponseFromResource(ProxyResponse proxyResponse, Resource resource) { + proxyResponse.setStatusCode(200); + proxyResponse.setStatusMessage(resource.getStatusMessage()); + proxyResponse.headers().addAll(resource.getHeaders()); + proxyResponse.setBody(Body.body(resource.getContent())); + } } diff --git a/src/main/java/io/vertx/httpproxy/spi/cache/Cache.java b/src/main/java/io/vertx/httpproxy/spi/cache/Cache.java index d269753..3531a07 100644 --- a/src/main/java/io/vertx/httpproxy/spi/cache/Cache.java +++ b/src/main/java/io/vertx/httpproxy/spi/cache/Cache.java @@ -24,7 +24,7 @@ public interface Cache { * Being called when the proxy attempts to fetch a cache item. * * @param key the URI of the resource - * @return the cached response, null if not exist + * @return the cached response, null if not exist, should all wrap with future */ Future get(String key); diff --git a/src/main/java/io/vertx/httpproxy/spi/cache/Resource.java b/src/main/java/io/vertx/httpproxy/spi/cache/Resource.java index d3b8dd6..8921f53 100644 --- a/src/main/java/io/vertx/httpproxy/spi/cache/Resource.java +++ b/src/main/java/io/vertx/httpproxy/spi/cache/Resource.java @@ -55,13 +55,6 @@ public Resource(String absoluteUri, int statusCode, String statusMessage, MultiM this.etag = headers.get(HttpHeaders.ETAG); } - public void init(ProxyResponse proxyResponse) { - proxyResponse.setStatusCode(200); - proxyResponse.setStatusMessage(statusMessage); - proxyResponse.headers().addAll(headers); - proxyResponse.setBody(Body.body(content)); - } - private static class Cursor { int i; }