Example #1
0
        public override void Fetch(HttpRequestWrapper request, HttpResponseWrapper response)
        {
            if (request.getHeaders("If-Modified-Since") != null)
            {
                if (!request.isConcat)
                {
                    response.setStatus((int)HttpStatusCode.NotModified);
                }
                return;
            }

            String host = request.getHeaders("Host");

            if (!lockedDomainService.isSafeForOpenProxy(host))
            {
                // Force embedded images and the like to their own domain to avoid XSS
                // in gadget domains.
                return;
            }

            sRequest  rcr     = buildHttpRequest(request);
            sResponse results = fetcher.fetch(rcr);

            if (contentRewriterRegistry != null)
            {
                results = contentRewriterRegistry.rewriteHttpResponse(rcr, results);
            }

            if (!request.isConcat)
            {
                SetResponseHeaders(request, response.getResponse(), results);
                for (int i = 0; i < results.getHeaders().Count; i++)
                {
                    String name = results.getHeaders().GetKey(i);
                    if (!DISALLOWED_RESPONSE_HEADERS.Contains(name.ToLower()))
                    {
                        foreach (String value in results.getHeaders().GetValues(i))
                        {
                            response.AddHeader(name, value);
                        }
                    }
                }
            }

            if (request.getParameter("rewriteMime") != null)
            {
                response.setContentType(request.getParameter("rewriteMime"));
            }

            if (results.getHttpStatusCode() != (int)HttpStatusCode.OK)
            {
                response.setStatus((int)results.getHttpStatusCode());
            }
            else
            {
                response.setStatus((int)HttpStatusCode.OK);
            }
            response.Write(results.responseBytes);
        }
Example #2
0
        public override void Fetch(HttpRequestWrapper request, HttpResponseWrapper response)
        {
            sRequest rcr = buildHttpRequest(request);

            // Serialize the response
            sResponse results = requestPipeline.execute(rcr);

            // Rewrite the response
            if (contentRewriterRegistry != null)
            {
                results = contentRewriterRegistry.rewriteHttpResponse(rcr, results);
            }

            // Serialize the response
            String output = convertResponseToJson(rcr.getSecurityToken(), request, results);

            // Find and set the refresh interval
            SetResponseHeaders(request, response.getResponse(), results);

            response.setStatus((int)HttpStatusCode.OK);
            response.setContentType("application/json");
            response.getResponse().ContentEncoding = Encoding.UTF8;
            response.Write(Encoding.UTF8.GetBytes(UNPARSEABLE_CRUFT + output));
        }