Skip to content

Commit

Permalink
fix batch 4
Browse files Browse the repository at this point in the history
  • Loading branch information
wzy1935 committed Aug 14, 2024
1 parent 14f25f5 commit c90fe54
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
11 changes: 9 additions & 2 deletions src/main/java/io/vertx/httpproxy/impl/CachingFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private Future<Void> 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();
}

Expand Down Expand Up @@ -138,9 +138,16 @@ private Future<ProxyResponse> 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()));
}
}
2 changes: 1 addition & 1 deletion src/main/java/io/vertx/httpproxy/spi/cache/Cache.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Resource> get(String key);

Expand Down
7 changes: 0 additions & 7 deletions src/main/java/io/vertx/httpproxy/spi/cache/Resource.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit c90fe54

Please sign in to comment.