Toggle navigation
Home
org.eclipse.jetty.proxy.ProxyServlet to org.eclipse.jetty.proxy.AbstractProxyServlet
No. of Instances - 3
No. of Commits - 2
No. of Projects - {'jetty.project'}
Hierarchy/Composition: R_SUPER_T
Primitive Info: -
NameSpace: Internal -> Internal
Mapping:
Update Anonymous class
{ private Map<String,ContentResponse> cache=new HashMap<>(); private Map<String,ByteArrayOutputStream> temp=new HashMap<>(); @Override protected void service( HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ContentResponse cachedResponse=cache.get(request.getRequestURI()); if (cachedResponse != null) { response.setStatus(cachedResponse.getStatus()); response.addHeader(cacheHeader,"true"); response.getOutputStream().write(cachedResponse.getContent()); } else { super.service(request,response); } } @Override protected void onResponseContent( HttpServletRequest request, HttpServletResponse response, Response proxyResponse, byte[] buffer, int offset, int length, Callback callback){ ByteArrayOutputStream baos=temp.get(request.getRequestURI()); if (baos == null) { baos=new ByteArrayOutputStream(); temp.put(request.getRequestURI(),baos); } baos.write(buffer,offset,length); super.onResponseContent(request,response,proxyResponse,buffer,offset,length,callback); } @Override protected void onResponseSuccess( HttpServletRequest request, HttpServletResponse response, Response proxyResponse){ byte[] content=temp.remove(request.getRequestURI()).toByteArray(); ContentResponse cached=new HttpContentResponse(proxyResponse,content,null,null); cache.put(request.getRequestURI(),cached); super.onResponseSuccess(request,response,proxyResponse); } }
to
{ private Map<String,ContentResponse> cache=new HashMap<>(); private Map<String,ByteArrayOutputStream> temp=new HashMap<>(); @Override protected void service( HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ContentResponse cachedResponse=cache.get(request.getRequestURI()); if (cachedResponse != null) { response.setStatus(cachedResponse.getStatus()); response.addHeader(cacheHeader,"true"); response.getOutputStream().write(cachedResponse.getContent()); } else { super.service(request,response); } } @Override protected void onResponseContent( HttpServletRequest request, HttpServletResponse response, Response proxyResponse, byte[] buffer, int offset, int length, Callback callback){ ByteArrayOutputStream baos=temp.get(request.getRequestURI()); if (baos == null) { baos=new ByteArrayOutputStream(); temp.put(request.getRequestURI(),baos); } baos.write(buffer,offset,length); super.onResponseContent(request,response,proxyResponse,buffer,offset,length,callback); } @Override protected void onProxyResponseSuccess( HttpServletRequest request, HttpServletResponse response, Response proxyResponse){ byte[] content=temp.remove(request.getRequestURI()).toByteArray(); ContentResponse cached=new HttpContentResponse(proxyResponse,content,null,null); cache.put(request.getRequestURI(),cached); super.onProxyResponseSuccess(request,response,proxyResponse); } }