/** * 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); }
/** * Creates a new Preload from an xml node. * * @param preload The Preload to create * @throws SpecParserException When the href is not specified */ public Preload(XmlElement preload, Uri _base) { this._base = _base; href = XmlUtil.getUriAttribute(preload, "href"); if (href == null) { throw new SpecParserException("Preload/@href is missing or invalid."); } // Record all the associated views String viewNames = XmlUtil.getAttribute(preload, "views", ""); HashSet <String> views = new HashSet <String>(); foreach (String _s in viewNames.Split(',')) { String s = _s.Trim(); if (s.Length > 0) { views.Add(s.Trim()); } } this.views = views; auth = AuthType.Parse(XmlUtil.getAttribute(preload, "authz")); signOwner = XmlUtil.getBoolAttribute(preload, "sign_owner", true); signViewer = XmlUtil.getBoolAttribute(preload, "sign_viewer", true); Dictionary <String, String> attributes = new Dictionary <string, string>(); XmlNamedNodeMap attrs = preload.Attributes; for (int i = 0; i < attrs.Count; ++i) { XmlNode attr = attrs.Item(i); if (!KNOWN_ATTRIBUTES.Contains(attr.Name)) { attributes.Add(attr.Name, attr.Value); } } this.attributes = attributes; }
/** * @param elements List of all views, in order, that make up this view. * An ordered list is required per the spec, since values must * overwrite one another. * @throws SpecParserException */ public View(String name, List <XmlElement> elements, Uri _base) { this.name = name; this._base = _base; bool quirks = true; Uri href = null; String contentType = null; ContentType type = null; int preferredHeight = 0; int preferredWidth = 0; String auth = null; bool signOwner = true; bool signViewer = true; Dictionary <String, String> attributes = new Dictionary <string, string>(); StringBuilder content = new StringBuilder(); foreach (XmlElement element in elements) { contentType = XmlUtil.getAttribute(element, "type"); if (contentType != null) { ContentType newType = ContentType.Parse(contentType); if (type != null && newType != type) { throw new SpecParserException("You may not mix content types in the same view."); } else { type = newType; } } href = XmlUtil.getUriAttribute(element, "href", href); quirks = XmlUtil.getBoolAttribute(element, "quirks", quirks); preferredHeight = XmlUtil.getIntAttribute(element, "preferred_height"); preferredWidth = XmlUtil.getIntAttribute(element, "preferred_width"); auth = XmlUtil.getAttribute(element, "authz", auth); signOwner = XmlUtil.getBoolAttribute(element, "sign_owner", signOwner); signViewer = XmlUtil.getBoolAttribute(element, "sign_viewer", signViewer); content.Append(element.InnerText); XmlNamedNodeMap attrs = element.Attributes; for (int i = 0; i < attrs.Count; ++i) { XmlNode attr = attrs.Item(i); if (!KNOWN_ATTRIBUTES.Contains(attr.Name)) { attributes.Add(attr.Name, attr.Value); } } } this.content = content.ToString(); this.needsUserPrefSubstitution = this.content.Contains("__UP_"); this.quirks = quirks; this.href = href; this.rawType = contentType ?? "html"; this.type = type ?? ContentType.HTML; this.preferredHeight = preferredHeight; this.preferredWidth = preferredWidth; this.attributes = attributes; this.authType = AuthType.Parse(auth); this.signOwner = signOwner; this.signViewer = signViewer; if (type == ContentType.URL && this.href == null) { throw new SpecParserException("Content@href must be set when Content@type is \"url\"."); } }