Class CachingProxy

java.lang.Object
net.targetr.wtm3.net.http.proxy.Proxy
net.targetr.wtm3.net.http.proxy.cache.CachingProxy

public class CachingProxy extends Proxy
A proxy that caches responses from target servers to avoid repeated network requests. Extends the basic Proxy functionality by checking a local cache before sending a request.
  • Constructor Details

    • CachingProxy

      public CachingProxy(HttpRequest httpReq, String target, long maxAgeMillis)
      Creates a new caching proxy.
      Parameters:
      httpReq - The incoming HTTP request.
      target - The target URL to proxy to.
      maxAgeMillis - The maximum time in milliseconds to keep the response in the cache.
  • Method Details

    • getResponse

      public HttpResponse getResponse() throws Exception
      Makes the connection, sends request and returns a ProxyResponse object suitable for returning the proxied response to the client.
      Overrides:
      getResponse in class Proxy
      Returns:
      Response for proxying data from the target address. Or ErrorResponse.
      Throws:
      Exception - An exception occured while connecting to the target or sending request.
    • makeResponse

      protected ProxyResponse makeResponse() throws Exception
      Description copied from class: Proxy
      Creates a ProxyResponse to stream the response back.
      Overrides:
      makeResponse in class Proxy
      Returns:
      A new ProxyResponse instance.
      Throws:
      Exception - If an error occurs creating the response.