Skip to content

Commit bd50c0c

Browse files
committed
fix batch 4
1 parent ebf2d0c commit bd50c0c

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

Diff for: src/main/java/io/vertx/httpproxy/impl/CachingFilter.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ private Future<Void> sendAndTryCacheProxyResponse(ProxyContext context) {
4242
if (cached != null && response.getStatusCode() == 304) {
4343
// Warning: this relies on the fact that HttpServerRequest will not send a body for HEAD
4444
response.release();
45-
cached.init(response);
45+
fillResponseFromResource(response, cached);
4646
return context.sendResponse();
4747
}
4848

@@ -138,9 +138,16 @@ private Future<ProxyResponse> tryHandleProxyRequestFromCache(ProxyContext contex
138138
}
139139
proxyRequest.release();
140140
ProxyResponse proxyResponse = proxyRequest.response();
141-
resource.init(proxyResponse);
141+
fillResponseFromResource(proxyResponse, resource);
142142
return Future.succeededFuture(proxyResponse);
143143
});
144144

145145
}
146+
147+
public void fillResponseFromResource(ProxyResponse proxyResponse, Resource resource) {
148+
proxyResponse.setStatusCode(200);
149+
proxyResponse.setStatusMessage(resource.getStatusMessage());
150+
proxyResponse.headers().addAll(resource.getHeaders());
151+
proxyResponse.setBody(Body.body(resource.getContent()));
152+
}
146153
}

Diff for: src/main/java/io/vertx/httpproxy/spi/cache/Cache.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public interface Cache {
2424
* Being called when the proxy attempts to fetch a cache item.
2525
*
2626
* @param key the URI of the resource
27-
* @return the cached response, null if not exist
27+
* @return the cached response, null if not exist, should all wrap with future
2828
*/
2929
Future<Resource> get(String key);
3030

Diff for: src/main/java/io/vertx/httpproxy/spi/cache/Resource.java

-7
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,6 @@ public Resource(String absoluteUri, int statusCode, String statusMessage, MultiM
5555
this.etag = headers.get(HttpHeaders.ETAG);
5656
}
5757

58-
public void init(ProxyResponse proxyResponse) {
59-
proxyResponse.setStatusCode(200);
60-
proxyResponse.setStatusMessage(statusMessage);
61-
proxyResponse.headers().addAll(headers);
62-
proxyResponse.setBody(Body.body(content));
63-
}
64-
6558
private static class Cursor {
6659
int i;
6760
}

0 commit comments

Comments
 (0)