예제 #1
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);
        }
예제 #2
0
        /**
         * Injects preloads into the gadget output.
         *
         * If preloading fails for any reason, we just output an empty object.
         */
        private static void InjectPreloads(Gadget gadget, Node scriptTag)
        {
            IPreloads preloads = gadget.getPreloads();

            Dictionary <String, Object> preload = new Dictionary <string, object>();

            foreach (PreloadedData preloaded in preloads.getData())
            {
                foreach (var entry in preloaded.toJson())
                {
                    preload.Add(entry.Key, entry.Value);
                }
            }
            Text text = scriptTag.getOwnerDocument().createTextNode("gadgets.io.preloaded_=");

            text.appendData(JsonConvert.ExportToString(preload));
            text.appendData(";");
            scriptTag.appendChild(text);
        }