예제 #1
0
        private sRequest buildHttpRequest(HttpRequestWrapper request)
        {
            Uri url = ValidateUrl(request.getParameter(URL_PARAM));

            sRequest req = new sRequest(url);

            req.Container = getContainer(request);
            if (request.getParameter(GADGET_PARAM) != null)
            {
                req.setGadget(Uri.parse(request.getParameter(GADGET_PARAM)));
            }

            // Allow the rewriter to use an externally forced mime type. This is needed
            // allows proper rewriting of <script src="x"/> where x is returned with
            // a content type like text/html which unfortunately happens all too often
            req.RewriteMimeType = request.getParameter(REWRITE_MIME_TYPE_PARAM);

            req.setIgnoreCache(getIgnoreCache(request));
            // If the proxy request specifies a refresh param then we want to force the min TTL for
            // the retrieved entry in the cache regardless of the headers on the content when it
            // is fetched from the original source.
            if (request.getParameter(REFRESH_PARAM) != null)
            {
                int ttl = 0;
                int.TryParse(request.getParameter(REFRESH_PARAM), out ttl);
                req.CacheTtl = ttl;
            }

            return(req);
        }
예제 #2
0
        /**
         * Generate a remote content request based on the parameters
         * sent from the client.
         * @throws GadgetException
         */
        private sRequest buildHttpRequest(HttpRequestWrapper request)
        {
            Uri url = ValidateUrl(request.getParameter(URL_PARAM));

            sRequest req = new sRequest(url)
                           .setMethod(GetParameter(request, METHOD_PARAM, "GET"))
                           .setPostBody(request.getRequest().ContentEncoding.GetBytes(GetParameter(request, POST_DATA_PARAM, "")))
                           .setContainer(getContainer(request));

            String headerData = GetParameter(request, HEADERS_PARAM, "");

            if (headerData.Length > 0)
            {
                String[] headerList = headerData.Split('&');
                foreach (String header in headerList)
                {
                    String[] parts = header.Split('=');
                    if (parts.Length != 2)
                    {
                        throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR,
                                                  "Malformed header specified,");
                    }
                    req.addHeader(HttpUtility.UrlDecode(parts[0]), HttpUtility.UrlDecode(parts[1]));
                }
            }

            //removeUnsafeHeaders(req);

            req.setIgnoreCache("1".Equals(request.getParameter(NOCACHE_PARAM)));

            if (request.getParameter(GADGET_PARAM) != null)
            {
                req.Gadget = Uri.parse(request.getParameter(GADGET_PARAM));
            }

            // Allow the rewriter to use an externally forced mime type. This is needed
            // allows proper rewriting of <script src="x"/> where x is returned with
            // a content type like text/html which unfortunately happens all too often
            req.setRewriteMimeType(request.getParameter(REWRITE_MIME_TYPE_PARAM));

            // Figure out whether authentication is required
            AuthType auth = AuthType.Parse(GetParameter(request, AUTHZ_PARAM, null));

            req.AuthType = auth;
            if (auth != AuthType.NONE)
            {
                req.setSecurityToken(extractAndValidateToken(request.getContext()));
                req.setOAuthArguments(new OAuthArguments(auth, request.getRequest()));
            }
            return(req);
        }
예제 #3
0
        /**
         * Creates a proxy request by fetching pipelined data and adding it to an existing request.
         *
         */
        private sRequest createPipelinedProxyRequest(Gadget gadget, sRequest original)
        {
            sRequest request = new sRequest(original);

            request.setIgnoreCache(true);
            GadgetSpec    spec          = gadget.getSpec();
            GadgetContext context       = gadget.getContext();
            IPreloads     proxyPreloads = preloader.preload(context, spec,
                                                            PreloaderService.PreloadPhase.PROXY_FETCH);

            // TODO: Add current url to GadgetContext to support transitive proxying.

            // POST any preloaded content
            if ((proxyPreloads != null) && proxyPreloads.getData().Count != 0)
            {
                JsonArray array = new JsonArray();

                foreach (PreloadedData preload in proxyPreloads.getData())
                {
                    Dictionary <String, Object> dataMap = preload.toJson();
                    foreach (var entry in dataMap)
                    {
                        // TODO: the existing, supported content is JSONObjects that contain the
                        // key already.  Discarding the key is odd.
                        array.Put(entry.Value);
                    }
                }

                String postContent = array.ToString();
                // POST the preloaded content, with a method override of GET
                // to enable caching
                request.setMethod("POST")
                .setPostBody(Encoding.UTF8.GetBytes(postContent))
                .setHeader("Content-Type", "text/json;charset=utf-8");
            }
            return(request);
        }