示例#1
0
        public void ClearTest()
        {
            // clear filled
            var dict = new Headers <RequestHeader>();

            dict.Set(RequestHeader.Accept, "value");
            dict.Set("Custom1", "value");
            Assert.Equal(2, dict.Count);
            dict.Clear();
            Assert.Equal(0, dict.Count);
            Assert.False(dict.Contains(RequestHeader.Accept));
            Assert.False(dict.Contains("Accept"));
            Assert.False(dict.Contains("Custom1"));

            // clear new
            dict = new Headers <RequestHeader>();
            dict.Clear();
            dict = new Headers <RequestHeader>(new NameValueCollection());
            dict.Clear();
            dict = new Headers <RequestHeader>(new Dictionary <string, string>());
            dict.Clear();

            // clear empty
            dict = new Headers <RequestHeader>();
            dict.Set(RequestHeader.Trailer, "value");
            dict.Remove(RequestHeader.Trailer);
            dict.Clear();
            Assert.Equal(0, dict.Count);
            Assert.False(dict.Contains(RequestHeader.Trailer));

            // clear cleared
            dict = new Headers <RequestHeader>();
            dict.Clear();
            dict.Clear();
        }
示例#2
0
        public void ImportClipboard()
        {
            Headers.Clear();
            Cards.Clear();
            Mappings.Clear();
            NameHeader      = null;
            SizeHeader      = null;
            IdHeader        = null;
            AlternateHeader = null;

            var clipboard = Clipboard.GetDataObject();

            if (clipboard.GetDataPresent("Xml Spreadsheet"))
            {
                StreamReader stream = new StreamReader((MemoryStream)clipboard.GetData("Xml Spreadsheet"));
                stream.BaseStream.SetLength(stream.BaseStream.Length - 1);
                XmlDocument xml = new XmlDocument();
                xml.LoadXml(stream.ReadToEnd());
                ParseXml(xml);
                StatusMessage = string.Format("Successfully imported {0} headers.", Headers.Count());

                NameHeader = new PropertyMappingItem()
                {
                    Property = ViewModelLocator.PropertyTabViewModel.NameProperty,
                    Header   = Headers.FirstOrDefault(x => x.PropertyName.Equals("Name", StringComparison.InvariantCultureIgnoreCase))
                };
                RaisePropertyChanged("NameHeader");
                SizeHeader = new PropertyMappingItem()
                {
                    Property = ViewModelLocator.PropertyTabViewModel.SizeProperty,
                    Header   = Headers.FirstOrDefault(x => x.PropertyName.Equals("Size", StringComparison.InvariantCultureIgnoreCase))
                };
                RaisePropertyChanged("SizeHeader");
                IdHeader = new PropertyMappingItem()
                {
                    Property = ViewModelLocator.PropertyTabViewModel.IdProperty,
                    Header   = Headers.FirstOrDefault(x => x.PropertyName.Equals("Id", StringComparison.InvariantCultureIgnoreCase))
                };
                RaisePropertyChanged("IdHeader");
                AlternateHeader = new PropertyMappingItem()
                {
                    Property = ViewModelLocator.PropertyTabViewModel.AlternateProperty,
                    Header   = Headers.FirstOrDefault(x => x.PropertyName.Equals("Alternate", StringComparison.InvariantCultureIgnoreCase))
                };
                RaisePropertyChanged("AlternateHeader");
                foreach (PropertyItemModel customprop in ViewModelLocator.PropertyTabViewModel.Items)
                {
                    Mappings.Add(new PropertyMappingItem()
                    {
                        Property = customprop,
                        Header   = Headers.FirstOrDefault(x => x.PropertyName.Equals(customprop.Name, StringComparison.InvariantCultureIgnoreCase))
                    });
                }
            }
            else
            {
                StatusMessage = "Invalid Clipboard Data";
            }
            RaisePropertyChanged("StatusMessage");
        }
        WebRequest SetupRequest(Uri uri, string method, CallbackData callbackData)
        {
            callback_data = callbackData;
            WebRequest request = GetWebRequest(uri);

            // do not send a relative URI to Determine method
            request.Method = DetermineMethod(request.RequestUri, method);
            // copy headers to the request - some needs special treatments
            foreach (string header in Headers)
            {
                switch (header.ToLowerInvariant())
                {
                case "content-length":
                    long cl = 0;
                    if (Int64.TryParse(Headers [header], out cl) && (cl >= 0))
                    {
                        request.ContentLength = cl;
                    }
                    break;

                case "accept":
                case "content-type":
                    // this skip the normal/user validation on headers
                    request.Headers.SetHeader(header, Headers [header]);
                    break;

                default:
                    request.Headers [header] = Headers [header];
                    break;
                }
            }
            // original headers are removed after calls
            Headers.Clear();
            return(request);
        }
示例#4
0
 private void ClearParameters()
 {
     Body = null;
     Query.Clear();
     Headers.Clear();
     FormBody.Clear();
 }
示例#5
0
        protected override async void PerformNavigate()
        {
            try
            {
                var uri      = new Uri(Address);
                var host     = uri.Host;
                var resource = uri.PathAndQuery;
                var port     = uri.Port;

                var sc = new SkClient(host, port);

                var request = RequestFactory.CreateHead(resource);

                using (var ms = new MemoryStream())
                {
                    var response = await sc.ExecuteAsync(request, ms, progressIndicator);

                    Status = response.StatusCode + " " + response.ReasonPhase;

                    Headers.Clear();
                    foreach (var header in response.Headers)
                    {
                        Headers.Add(header.Key + ": " + header.Value);
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
示例#6
0
 public void RestoreRegion(IToolRegion toRestore)
 {
     if (toRestore is WebPutInputRegion region)
     {
         IsEnabled   = region.IsEnabled;
         QueryString = region.QueryString;
         RequestUrl  = region.RequestUrl;
         Headers.Clear();
         Headers.Add(new ObservableAwareNameValue(Headers, s =>
         {
             _modelItem.SetProperty("Headers",
                                    _headers.Select(a => new NameValue(a.Name, a.Value) as INameValue).ToList());
         }));
         if (region.Headers != null)
         {
             foreach (var nameValue in region.Headers)
             {
                 Headers.Add(new ObservableAwareNameValue(Headers, s =>
                 {
                     _modelItem.SetProperty("Headers",
                                            _headers.Select(a => new NameValue(a.Name, a.Value) as INameValue).ToList());
                 })
                 {
                     Name = nameValue.Name, Value = nameValue.Value
                 });
             }
             Headers.Remove(Headers.First());
         }
     }
 }
        private bool WriteJsonResponse(string a_szResponse)
        {
            // Convert the JSON to UTF8...
            var abBufferJson = Encoding.UTF8.GetBytes(a_szResponse);

            // Fix the header in our response...
            Headers.Clear();
            Headers.Add(HttpResponseHeader.ContentType, "application/json; charset=UTF-8");
            ContentLength64 = abBufferJson.Length;

            // We need some protection...
            try
            {
                // Get a response stream and write the response to it...
                var streamResponse = OutputStream;
                streamResponse.Write(abBufferJson, 0, abBufferJson.Length);

                // Close the output stream...
                streamResponse.Close();
            }
            catch (Exception exception)
            {
                // This is most likely to happen if we lose communication,
                // or if the application poos itself at an inopportune
                // moment...
                Log.Error("response failed - " + exception.Message);
                return(false);
            }

            // All done...
            return(true);
        }
示例#8
0
 /// <summary>
 ///     Copy headers from the inner content.
 /// </summary>
 void LoadHeaders()
 {
     Headers.Clear();
     foreach (var header in _innerContent.Headers)
     {
         Headers.TryAddWithoutValidation(header.Key, header.Value);
     }
 }
示例#9
0
 /// <summary>
 /// 重置 头部
 /// </summary>
 public void ResetHeaders()
 {
     Headers.Clear();
     Headers.Add(HttpRequestHeader.Accept, "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
     Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
     Headers.Add(HttpRequestHeader.AcceptLanguage, _acceptLanguage);
     Headers.Add(HttpRequestHeader.UserAgent, _userAgent);
 }
示例#10
0
        public void AddSecurityHeaders()
        {
            Headers.Clear();
            Headers.Add(HttpRequestHeader.ContentType, "application/json");
            Headers.Add("Authorization", $"Bearer {BearerToken}");

            Encoding = System.Text.Encoding.UTF8;
        }
示例#11
0
        void Columns_ItemsCleared(object sender, EventArgs e)
        {
            // clear frames&headers
            Frames.Clear();
            Headers.Clear();

            _rows.Clear();
        }
示例#12
0
 protected void ParseHeaders()
 {
     Headers.Clear();
     for (int x = 0; x < HttpResponse.Headers.Count; x++)
     {
         Headers.Add(new HttpHeader.GeneralHeader(HttpResponse.Headers.Keys[x], HttpResponse.Headers[x]));
     }
 }
示例#13
0
 public void Dispose()
 {
     Cookies.Clear();
     Files.Clear();
     Parameters.Clear();
     RequestBody.Clear();
     Headers.Clear();
     Resource = null;
 }
示例#14
0
        public void Dispose()
        {
            if (Content != null)
            {
                Content.Dispose();
            }

            Headers.Clear();
        }
示例#15
0
        void IDisposable.Dispose()
        {
            if (Content != null)
            {
                Content.Dispose();
            }

            Headers.Clear();
        }
示例#16
0
 public void Reset()
 {
     Uri = null;
     Document.RemoveAll();
     AcceptHeader = null;
     Headers.Clear();
     Cookies = new CookieContainer();
     //Clear cookies
 }
 /// <summary>
 /// Parses Request HTTP headers from a string into the
 /// Headers property of this class
 /// </summary>
 /// <param name="headerText">Full set of Http Request Headers</param>
 public void ParseHttpHeaders(string headerText)
 {
     if (string.IsNullOrEmpty(headerText))
     {
         Headers.Clear();
         return;
     }
     ParseHttpHeaders(StringUtils.GetLines(headerText));
 }
示例#18
0
 public void ResetHeaders()
 {
     Headers.Clear();
     Headers.Add(HttpRequestHeader.Accept, "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
     Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
     Headers.Add(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.8");
     Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)");
     //Headers.Add(HttpRequestHeader.UserAgent, "Baiduspider+(+http://www.baidu.com/search/spider.htm)");
 }
示例#19
0
        public bool init(string fileName)
        {
            FileName = fileName;
            Headers.Clear();
            Dates.Clear();
            Data.Clear();

            return(File.Exists(fileName));
        }
示例#20
0
 private void RunCompressedResponse(string acceptEncoding, bool include)
 {
     Headers.Clear();
     if (include)
     {
         Headers.Add("Accept-Encoding", acceptEncoding);
     }
     CompressedCssResponse.WriteCss("");
 }
示例#21
0
 public void ResetContext()
 {
     //https://stackoverflow.com/questions/1978821/how-to-reset-a-dictionary
     HTTPVerb        = "";
     HttpProtokoll   = "";
     MessageEndPoint = "";
     Headers.Clear();
     PayLoad = "";
 }
        private void RunQuery()
        {
            IMongoQuery mongoQuery = _mongoQueryFactory.BuildQuery();
            IEnumerable documents  = null;

            try
            {
                documents = mongoQuery.RunQuery(Server, Database, Port, Query);

                Headers.Clear();
                Items.Clear();

                foreach (IDictionary document in documents)
                {
                    ItemViewModel model = new ItemViewModel(Headers);

                    foreach (string key in document.Keys)
                    {
                        string k = key;
                        if (Headers.SingleOrDefault(field => field.FieldName == k) == null)
                        {
                            Headers.Add(new FieldViewModel()
                            {
                                FieldName = key
                            });
                        }

                        model.Data[key] = document[key].ToString();
                    }

                    Items.Add(model);
                }

                NumberOfResults = string.Format("{0}: {1} docs", DateTime.Now.ToString("HH:mm:ss"), Items.Count);

                ListViewExtension.RefreshUI(Headers);
            }
            catch (QueryValidationException ex)
            {
                _userMessageService.ShowMessage(ex.Message);
                return;
            }
            catch (UnknownServerException ex)
            {
                _userMessageService.ShowMessage(ex.Message);
                return;
            }
            catch (Exception ex)
            {
                _userMessageService.ShowMessage("An error occurred while executing the query: " + ex);
                return;
            }
            finally
            {
                mongoQuery.Dispose();
            }
        }
示例#23
0
        private HttpWebRequest CreateRequest(Uri url, HttpVerb verb)
        {
            var request = (HttpWebRequest)WebRequest.Create(url.AbsoluteUri);

            request.Referer                = referer != null ? referer.AbsoluteUri : null;
            request.Method                 = ToMethod(verb);
            request.CookieContainer        = cookieContainer;
            request.UserAgent              = UserAgent.UserAgent;
            request.Proxy                  = Proxy;
            request.AutomaticDecompression = DecompressionMethods;

            request.Headers["Accept-Language"] = Language.Name;

            if (Headers != null)
            {
                foreach (var header in Headers)
                {
                    if (header.Key.ToLower() == "accept")
                    {
                        request.Accept = header.Value;
                    }
                    else if (header.Key.ToLower() == "referer")
                    {
                        request.Referer = header.Value;
                    }
                    else
                    {
                        request.Headers[header.Key] = header.Value;
                    }
                }

                Headers.Clear();
            }

            request.CachePolicy = CachePolicy;

            if (Timeout > TimeSpan.Zero)
            {
                request.Timeout = (int)Timeout.TotalMilliseconds;
            }

            request.KeepAlive       = KeepAlive;
            request.ProtocolVersion = ProtocolVersion;

            if (!string.IsNullOrWhiteSpace(TransferEncoding))
            {
                request.SendChunked      = true;
                request.TransferEncoding = TransferEncoding;
            }
            else
            {
                request.SendChunked = SendChunked;
            }

            return(request);
        }
示例#24
0
        private void InitializeHeaders(int Count)
        {
            logger.Info("Entered");

            Headers.Clear();
            for (int i = 0; i < Count; i++)
            {
                Headers[i] = "F" + i.ToString();
            }
        }
        public AuthorizationRequest(NetworkIPSConfig environment) : base(HttpMethod.Post, "/identity/auth/access-token")
        {
            Headers.Clear();
            Headers.Add("accept", "application/vnd.ni-identity.v1+json");
            Headers.Authorization = new AuthenticationHeaderValue("Basic", environment.ApiKey);
            var f = new System.Net.Http.StringContent("{\"realmName\":\"ni\"}", Encoding.UTF8, "application/json");

            this.Content = f;
            this.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.ni-identity.v1+json");
        }
        private void Fill(SuperexpressDrawModel draw, SuperexpressDrawInfoModel drawInfo)
        {
            Headers.Clear();
            Events.Clear();

            var outcomesIds = draw.Events
                              .SelectMany(x => x.Coefficients)
                              .Select(x => x.Outcome)
                              .Select(x => x.Id)
                              .Distinct();

            foreach (var outcome in outcomesIds)
            {
                var outcomeName = draw.Events.SelectMany(x => x.Coefficients).FirstOrDefault(x => x.Outcome.Id == outcome).Outcome.Name;
                Headers.Add(outcomeName);
            }


            foreach (var item in draw.Events)
            {
                var ev = new EventViewModel
                {
                    Id   = item.ID,
                    Name = item.Name,
                    Path = item.BranchPathName
                };

                foreach (var outcome in outcomesIds)
                {
                    var coefficient = item.Coefficients
                                      .Where(x => x.Outcome.Id == outcome)
                                      .Select(x => new CoefficientViewModel
                    {
                        Id         = x.Id,
                        Name       = x.Outcome.Name,
                        IsSelected = false
                    })
                                      .FirstOrDefault();

                    if (coefficient != null)
                    {
                        coefficient.SelectedChanged += CoefficientSelectedChanged;
                    }

                    ev.Coefficients.Add(coefficient);
                }

                Events.Add(ev);
            }

            CalculateVariantsAmount();

            DrawChanged?.Invoke(this);
        }
示例#27
0
        // Interface
        public virtual void Clear()
        {
            _data = null;
            Title = null;

            Headers.Clear();
            Cookies.Clear();

            // Defaults
            Version = "HTTP/1.1";
            Socket  = HttpTag.KeepAlive;
        }
示例#28
0
        void Columns_ItemsSorted(object sender, EventArgs e)
        {
            // we clear frames/headers
            Headers.Clear();
            Frames.Clear();

            // and add them again in the new order
            foreach (var column in Columns)
            {
                Headers.Add(column.Header);
                Frames.Add(column.Frame);
            }
        }
示例#29
0
        void SourceOnSomethingChanged(object sender, IToolRegion args)
        {
            if (_source?.SelectedSource != null)
            {
                RequestUrl = _source.SelectedSource.HostName;
                QueryString = _source.SelectedSource.DefaultQuery;
                Headers.Clear();
                AddHeaders();
                IsEnabled = true;
            }

            OnPropertyChanged(nameof(IsEnabled));
        }
示例#30
0
        /// <summary>
        /// Imports data from a csv file
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="separator"></param>
        public void FromCsvStream(Stream stream, char separator = ',')
        {
            using var sr = new StreamReader(stream);

            // first line is the header
            Headers.Clear();
            var headerline = sr.ReadLine();

            if (string.IsNullOrEmpty(headerline))
            {
                return;
            }

            var array = headerline.Split(separator);

            for (var i = 0; i < array.Length; i++)
            {
                var item    = array[i];
                var cstring = new CString(cr2w, Headers, i.ToString());
                cstring.SetValue(item);
                Headers.Add(cstring);
            }
            Headers.IsSerialized = true;

            // read elements
            string line;
            var    cnt = 0;

            while ((line = sr.ReadLine()) != null)
            {
                // check if same columns as header
                var columns = line.Split(separator);
                if (columns.Length != Headers.Count)
                {
                    throw new SerializationException();
                }

                var row = new CArray <CString>(cr2w, Data, cnt.ToString());
                for (var i = 0; i < columns.Length; i++)
                {
                    var item    = columns[i];
                    var cstring = new CString(cr2w, null, i.ToString());
                    cstring.SetValue(item);
                    row.Add(cstring);
                }

                Data.Add(row);
                cnt++;
            }
            Data.IsSerialized = true;
        }