diff --git a/service/middleware.go b/service/middleware.go index b77f2f1..df88d70 100644 --- a/service/middleware.go +++ b/service/middleware.go @@ -16,6 +16,7 @@ import ( "github.com/kava-labs/kava-proxy-service/config" "github.com/kava-labs/kava-proxy-service/decode" "github.com/kava-labs/kava-proxy-service/logging" + "github.com/kava-labs/kava-proxy-service/service/cachemdw" ) const ( @@ -228,8 +229,11 @@ func createProxyRequestMiddleware(next http.Handler, config config.Config, servi serviceLogger.Trace().Msg("request body is empty, skipping before request interceptors") } - // proxy request to backend origin servers - proxy.ServeHTTP(lrw, r) + // Only proxy the request if it's not cached + isCached := cachemdw.IsRequestCached(r.Context()) + if !isCached { + proxy.ServeHTTP(lrw, r) + } serviceLogger.Trace().Msg(fmt.Sprintf("response %+v \nheaders %+v \nstatus %+v for request %+v", lrw.Status(), lrw.Header(), lrw.body, r)) @@ -383,6 +387,7 @@ func createAfterProxyFinalizer(service *ProxyService, config config.Config) http } var blockNumber *int64 + // TODO: Redundant ExtractBlockNumberFromEVMRPCRequest call here if request is cached rawBlockNumber, err := decodedRequestBody.ExtractBlockNumberFromEVMRPCRequest(r.Context(), service.evmClient) if err != nil {