Пример #1
0
        public FormWebRequest(string method, string urlAbsolute, Dictionary <string, string> requestHeaders, string requestBody, Dictionary <string, string> responseHeaders, string responseBody)
            : this()
        {
            this.cmbVerb.Text                 = method;
            this.txtUrl.TextValue             = urlAbsolute;
            this.txtRequestHeaders.TextValue  = HttpUtils.GetHeadersAsString(requestHeaders);
            this.txtRequestBody.TextValue     = Helper.ResolveBreakLineInCompatibility(requestBody);
            this.txtResponseHeaders.TextValue = HttpUtils.GetHeadersAsString(responseHeaders);
            this.txtResponseBody.TextValue    = Helper.ResolveBreakLineInCompatibility(responseBody);
            if (string.IsNullOrWhiteSpace(requestBody) && !string.IsNullOrWhiteSpace(this.txtRequestHeaders.TextValue))
            {
                tabRequest.SelectedTab = tabRequestHeaders;
            }

            if (string.IsNullOrWhiteSpace(responseBody) && !string.IsNullOrWhiteSpace(this.txtResponseHeaders.TextValue))
            {
                tabResponse.SelectedTab = tabResponseHeaders;
            }

            var contentType = HttpUtils.GetHeaderValue(requestHeaders, "content-type");

            if (contentType != null)
            {
                contentType = contentType.ToLower();
                if (contentType.Contains("xml"))
                {
                    txtRequestBody.Language = AdvancedEditor.LanguageSupported.XML;
                }
                else if (contentType.Contains("html"))
                {
                    txtRequestBody.Language = AdvancedEditor.LanguageSupported.HTML;
                }
                else if (contentType.Contains("json"))
                {
                    txtRequestBody.Language = AdvancedEditor.LanguageSupported.Json;
                }
                else if (contentType.Contains("javascript"))
                {
                    txtRequestBody.Language = AdvancedEditor.LanguageSupported.JS;
                }
            }

            if (!string.IsNullOrWhiteSpace(this.txtRequestBody.TextValue))
            {
                tabRequest.SelectedTab = tabRequestBody;
            }
        }
Пример #2
0
        private async void ShowResponse(DateTime t1, DateTime t2, HttpWebRequest request, HttpWebResponse response)
        {
            using (var s = response.GetResponseStream())
            {
                using (var sr = new StreamReader(s, Encoding.UTF8))
                {
                    var content = await sr.ReadToEndAsync();

                    txtResponseBody.TextValue = Helper.ResolveBreakLineInCompatibility(content);
                }
            }

            var headers = HttpUtils.GetHeaders(response);

            stsTimeValue.Text   = (t2 - t1).ToString();
            stsStatusValue.Text = $"{(int)response.StatusCode} ({response.StatusDescription})";
            txtRequestHeadersFinal.TextValue = HttpUtils.GetHeadersAsString(headers);
            txtResponseHeaders.TextValue     = $"{(int)response.StatusCode} {response.StatusDescription}\r\n";
            txtResponseHeaders.TextValue    += HttpUtils.GetHeadersAsString(HttpUtils.GetHeaders(response));
            btnExecute.Enabled = true;

            var contentType = HttpUtils.GetHeaderValue(headers, "content-type");

            if (contentType != null)
            {
                contentType = contentType.ToLower();
                if (contentType.Contains("xml"))
                {
                    txtResponseBody.Language = AdvancedEditor.LanguageSupported.XML;
                }
                else if (contentType.Contains("html"))
                {
                    txtResponseBody.Language = AdvancedEditor.LanguageSupported.HTML;
                }
                else if (contentType.Contains("json"))
                {
                    txtResponseBody.Language = AdvancedEditor.LanguageSupported.Json;
                }
                else if (contentType.Contains("javascript"))
                {
                    txtResponseBody.Language = AdvancedEditor.LanguageSupported.JS;
                }
            }
        }
Пример #3
0
        private ContextMenuStrip GetMenuTripRow(LogRow row)
        {
            // context menu
            var menu               = new ContextMenuStrip();
            var viewRequestMenu    = new ToolStripMenuItem();
            var viewResponseMenu   = new ToolStripMenuItem();
            var viewRawMenu        = new ToolStripMenuItem();
            var viewInComposerMenu = new ToolStripMenuItem();
            var compareMenu        = new ToolStripMenuItem();

            menu.Items.AddRange(new ToolStripMenuItem[]
            {
                viewRequestMenu,
                viewResponseMenu,
                viewRawMenu,
                viewInComposerMenu,
                compareMenu
            });

            menu.Opening += (a, b) =>
            {
                if (row.Request == null)
                {
                    viewRawMenu.Visible        = true;
                    viewRequestMenu.Visible    = false;
                    viewResponseMenu.Visible   = false;
                    viewInComposerMenu.Visible = false;
                    compareMenu.Visible        = false;
                }
                else
                {
                    viewRawMenu.Visible        = false;
                    viewRequestMenu.Visible    = true;
                    viewResponseMenu.Visible   = true;
                    viewInComposerMenu.Visible = true;
                    compareMenu.Visible        = true;
                }
            };

            // view request
            viewRequestMenu.Text   = Resource.viewRequestMenu;
            viewRequestMenu.Click += (a, b) =>
            {
                var frmStart = new FormTextView(master, row.UrlAbsolute, row.RequestLog.ToString());
                master.TabMaster.AddTab(frmStart, row, row.Url + " (Request)");
            };

            // view response
            viewResponseMenu.Text   = Resource.viewResponseMenu;
            viewResponseMenu.Click += (a, b) =>
            {
                var frmStart = new FormTextView(master, row.UrlAbsolute, row.Response.ToString());
                master.TabMaster.AddTab(frmStart, row, row.Url + " (Response)");
            };

            // view raw
            viewRawMenu.Text   = Resource.viewRawMenu;
            viewRawMenu.Click += (a, b) =>
            {
                var frmStart = new FormTextView(master, row.UrlAbsolute, row.Raw);
                master.TabMaster.AddTab(frmStart, row, row.Url + " (Raw)");
            };

            // view in composer
            viewInComposerMenu.Text   = Resource.viewInComposerMenu;
            viewInComposerMenu.Click += (a, b) =>
            {
                var requestHeaders  = GetHeaders(row.RequestLog);
                var requestBody     = row.RequestLog.getBodyAsString();
                var responseHeaders = GetHeaders(row.Response);
                var responseBody    = row.Response.getBodyAsString();

                var frmComposer = new FormWebRequest(row.Method, row.UrlAbsolute, requestHeaders, requestBody, responseHeaders, responseBody);
                master.TabMaster.AddTab(frmComposer, row, row.Url);
            };

            // view in composer
            compareMenu.Text   = Resource.compareMenu;
            compareMenu.Click += (a, b) =>
            {
                var           strBuilder          = new StringBuilder();
                StringBuilder strBuilderFormatted = null;
                var           requestHeaders      = GetHeaders(row.RequestLog);
                var           requestBody         = row.RequestLog.getBodyAsString();

                strBuilder.AppendLine($"{row.Method} {row.UrlAbsolute}");
                strBuilder.AppendLine();
                if (requestBody?.Length == 0)
                {
                    strBuilder.Append(GetHeadersAsString(requestHeaders));
                }
                else
                {
                    var strHeaders = GetHeadersAsString(requestHeaders);

                    strBuilder.AppendLine(strHeaders);
                    strBuilder.AppendLine();
                    strBuilder.Append(requestBody);

                    // formatted body
                    var    contentType          = HttpUtils.GetHeaderValue(row.Headers, "content-type");
                    string requestBodyFormatted = null;
                    if (contentType?.ToLower().Contains("json") == true)
                    {
                        requestBodyFormatted = Helper.FormatToJson(requestBody, false);
                    }
                    else if (contentType?.ToLower().Contains("xml") == true)
                    {
                        requestBodyFormatted = Helper.FormatToXml(requestBody, false);
                    }

                    if (requestBodyFormatted != null)
                    {
                        strBuilderFormatted = new StringBuilder();
                        strBuilderFormatted.AppendLine(strHeaders);
                        strBuilderFormatted.AppendLine();
                        strBuilderFormatted.Append(requestBodyFormatted);
                    }
                }

                var frmCompare = new FormCompare(this.master, strBuilderFormatted?.ToString() ?? strBuilder.ToString());
                master.TabMaster.AddTab(frmCompare, row, row.Url);
            };


            return(menu);
        }