Exemple #1
0
 private static object GetRequestAsBytes(DreamContext context, DreamMessage request, Result <DreamMessage> response)
 {
     return(request.ToBytes());
 }
Exemple #2
0
        //--- Constructors ---
        /// <summary>
        /// Serialize message into Xml.
        /// </summary>
        /// <param name="message">Message to serialize.</param>
        public XMessage(DreamMessage message)
            : base("message")
        {
            Elem("status", (int)message.Status);
            Start("headers");
            foreach(KeyValuePair<string, string> pair in message.Headers) {
                Elem(pair.Key, pair.Value ?? string.Empty);
            }
            if(message.HasCookies) {
                foreach(DreamCookie cookie in message.Cookies) {

                    // NOTE (steveb): we rely on the 'Version' being set to differentiate between 'Cookie' and a 'Set-Cookie' headers

                    if(cookie.Version != 0) {
                        Add(cookie.AsSetCookieDocument);
                    } else {
                        Add(cookie.AsCookieDocument);
                    }
                }
            }
            End();
            Start("body");
            if(message.HasDocument) {
                Attr("format", "xml").Add(message.ToDocument());
            } else {
                byte[] bytes = message.ToBytes();
                string body = null;
                string attr = "none";

                // TODO (steveb): we need to use a content-type matching algorithm and match against all known text types (text/*, application/json, etc.)
                if(bytes.Length > 0) {
                    if(message.ContentType.Match(MimeType.ANY_TEXT)) {
                        body = message.ContentType.CharSet.GetString(bytes).EncodeHtmlEntities(Encoding.UTF8, false);
                        attr = "text";
                    } else {
                        body = Convert.ToBase64String(bytes);
                        attr = "base64";
                    }
                }
                Attr("format", attr).Value(body);
            }
            End();
        }
Exemple #3
0
 private static object GetRequestAsBytes(DreamContext context, DreamMessage request, Result<DreamMessage> response)
 {
     return request.ToBytes();
 }
Exemple #4
0
        internal Yield PostConvert(DreamContext context, DreamMessage request, Result<DreamMessage> response)
        {
            // TODO (2014-11-25, steveb): what is this used for?

            response.Return(DreamMessage.Ok(request.ContentType, request.ToBytes()));
            yield break;
        }
Exemple #5
0
 internal Yield PostConvert(DreamContext context, DreamMessage request, Result<DreamMessage> response)
 {
     response.Return(DreamMessage.Ok(request.ContentType, request.ToBytes()));
     yield break;
 }
Exemple #6
0
        private void SetRequestResult(DreamMessage result, XUri uri)
        {
            String tempfilename = String.Empty;

            _cookies.Update(result.Cookies, uri);

            txtHeaders.Clear();
            foreach (KeyValuePair<string, string> header in result.Headers) {
                txtHeaders.Text += header.Key + " = " + header.Value + Environment.NewLine;
            }

            foreach (DreamCookie c in result.Cookies) {
                txtHeaders.Text += string.Format("Cookie: '{0}' Value: '{1}' Path: '{2}', Expires: '{3}' Domain: '{4}' {5}", c.Name, c.Value, c.Path, c.Expires, c.Domain, Environment.NewLine);
            }

            // if we received a file, save it
            if (!String.IsNullOrEmpty(result.Headers[DreamHeaders.CONTENT_DISPOSITION])) {
                String filename;
                String[] contentInfoList = result.Headers[DreamHeaders.CONTENT_DISPOSITION].Split(';');
                foreach (String contentInfo in contentInfoList) {
                    String trimmedContentInfo = contentInfo.Trim();
                    if (StringUtil.StartsWithInvariantIgnoreCase(trimmedContentInfo, "filename=")) {
                        filename = trimmedContentInfo.Substring(9);
                        filename = filename.Trim('"', '\\');
                        tempfilename = Path.Combine(Path.GetTempPath(), filename);
                        result.ToStream().CopyToFile(tempfilename, result.ContentLength);
                    }
                }
            } else {
                tempfilename = Path.Combine(Path.GetTempPath(), DateTime.Now.Ticks.ToString()) + ".xml";
                RegistryKey key = Registry.ClassesRoot.OpenSubKey("MIME\\Database\\Content Type\\" + result.ContentType.FullType);
                if (null != key) {
                    tempfilename = tempfilename + key.GetValue("Extension");
                    key.Close();
                }
                File.WriteAllBytes(tempfilename, result.ToBytes());
            }

            // browse to the saved temporary file
            if (!String.IsNullOrEmpty(tempfilename))
            {
                webBrowser.Url = new Uri(tempfilename);
            }
            else{
                webBrowser.Url = null;
            }

            tabControl1.SelectedTab = resultsTabPage;
        }