Ejemplo n.º 1
0
        public sResponse execute(sRequest request)
        {
            sResponse response;

            if (!request.IgnoreCache)
            {
                response = DefaultHttpCache.Instance.getResponse(request);
                if (response != null && !response.isStale())
                {
                    return(response);
                }
            }

            if (request.AuthType == AuthType.NONE)
            {
                response = httpFetcher.fetch(request);
            }
            else if (request.AuthType == AuthType.OAUTH || request.AuthType == AuthType.SIGNED)
            {
                response = oauthRequestProvider.get().fetch(request);
            }
            else
            {
                return(sResponse.error());
            }

            if (!request.IgnoreCache && response.getHttpStatusCode() == (int)HttpStatusCode.OK)
            {
                DefaultHttpCache.Instance.addResponse(request, response);
            }
            return(response);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        /**
         * Retrieves js content from the given url.
         *
         * @param url
         * @param fetcher
         * @return The contents of the JS file, or null if it can't be fetched.
         * @throws GadgetException
         */
        private static String LoadDataFromUrl(String url, IHttpFetcher fetcher)
        {
            // set up the request and response objects
            Uri       uri      = Uri.parse(url);
            sRequest  request  = new sRequest(uri);
            sResponse response = fetcher.fetch(request);

            if (response.getHttpStatusCode() == (int)HttpStatusCode.OK)
            {
                return(response.responseString);
            }
            return(null);
        }
        protected MessageBundle fetchBundle(LocaleSpec locale, bool ignoreCache)
        {
            Uri      url     = locale.getMessages();
            sRequest request = new sRequest(url).setIgnoreCache(ignoreCache);

            // Since we don't allow any variance in cache time, we should just force the cache time
            // globally. This ensures propagation to shared caches when this is set.
            request.setCacheTtl((int)(refresh / 1000));

            sResponse response = fetcher.fetch(request);

            if (response.getHttpStatusCode() != (int)HttpStatusCode.OK)
            {
                throw new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT,
                                          "Unable to retrieve message bundle xml. HTTP error " +
                                          response.getHttpStatusCode());
            }

            MessageBundle bundle = new MessageBundle(locale, response.responseString);

            return(bundle);
        }
        private GadgetSpec FetchObjectAndCache(Uri url, bool ignoreCache)
        {
            sRequest request = new sRequest(url)
                               .setIgnoreCache(ignoreCache)
                               .setGadget(url);

            // Since we don't allow any variance in cache time, we should just force the cache time
            // globally. This ensures propagation to shared caches when this is set.
            request.setCacheTtl((int)(refresh / 1000));

            sResponse response = fetcher.fetch(request);

            if (response.getHttpStatusCode() != (int)HttpStatusCode.OK)
            {
                throw new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT,
                                          "Unable to retrieve gadget xml. HTTP error " +
                                          response.getHttpStatusCode());
            }

            GadgetSpec spec = new GadgetSpec(url, response.responseString);

            HttpRuntime.Cache.Insert(url.ToString(), spec, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(refresh));
            return(spec);
        }
Ejemplo n.º 6
0
        private sResponse fetchFromServer(sRequest request)
        {
            sResponse response = null;

            try
            {
                response = fetcher.fetch(request);
                if (response == null)
                {
                    throw responseParams.oauthRequestException(OAuthError.UNKNOWN_PROBLEM,
                                                               "No response from server");
                }
                return(response);
            }
            catch (GadgetException e)
            {
                throw responseParams.oauthRequestException(
                          OAuthError.UNKNOWN_PROBLEM, "No response from server", e);
            }
            finally
            {
                responseParams.addRequestTrace(request, response);
            }
        }
Ejemplo n.º 7
0
 /**
 * Retrieves js content from the given url.
 *
 * @param url
 * @param fetcher
 * @return The contents of the JS file, or null if it can't be fetched.
 * @throws GadgetException
 */
 private static String LoadDataFromUrl(String url, IHttpFetcher fetcher)
 {
     
     // set up the request and response objects
     Uri uri = Uri.parse(url);
     sRequest request = new sRequest(uri);
     sResponse response = fetcher.fetch(request);
     if (response.getHttpStatusCode() == (int)HttpStatusCode.OK)
     {
         return response.responseString;
     }
     return null;
 }