/// <summary>
 /// Adds generic User-Agent, Accept-Language, Accept-Encoding, Accept, Dnt, and Upgrade-Insecure-Requests
 /// </summary>
 /// <param name="Header">Headers reference to add to</param>
 public static void AddBaseRequestHeaders(this HeaderCollection Header)
 {
     Header.AddItem("Accept-Language", "en-GB,en-US;q=0.9,en;q=0.8");
     //Header.AddItem("Accept-Encoding", "gzip, deflate");
     // Refer: -
     Header.AddItem("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*; q = 0.8");
     Header.AddItem("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Safari/537.36");
     Header.AddItem("Dnt", "1");
     Header.AddItem("Upgrade-Insecure-Requests", "1");
 }
Exemplo n.º 2
0
        public void Events_FetchCompleteEventArgs_Save_Base()
        {
            var lnk = new Link(LinkUseTests.Books, LinkUseTests.Quotes)
            {
                FetchStart = new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc),
                FetchEnd   = new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc),
            };
            var bytes = Encoding.ASCII.GetBytes("TEST TEST TEST");

            var req = new HeaderCollection();

            req.AddItem("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9");

            var resp = new HeaderCollection();

            resp.AddItem("Content-Type", "text/html; charset=UTF-8");
            resp.AddItem("Content-Length", "14");

            var args = new FetchCompleteEventArgs(lnk, bytes, req, resp);

            using var ms = new MemoryStream();
            FetchCompleteEventArgs.SaveFetchResult(args, ms);
            var arr     = ms.ToArray();
            var strComp = Encoding.ASCII.GetString(arr);

            Assert.Equal(
                @"--------------------LINK
Uri: http://books.toscrape.com/
SourceUri: http://quotes.toscrape.com/
FetchStart: 2020-01-01T00:00:00+00:00
FetchEnd: 2020-01-01T00:00:00+00:00

--------------------REQ-HDR
Accept: text/html,application/xhtml+xml,application/xml;q=0.9

--------------------RES-HDR
Content-Type: text/html; charset=UTF-8
Content-Length: 14

TEST TEST TEST", strComp);
        }
Exemplo n.º 3
0
        public void Events_FetchCompleteEventArgs_Cycle()
        {
            var lnk   = new Link(LinkUseTests.Books, LinkUseTests.Quotes);
            var bytes = Encoding.ASCII.GetBytes("TEST TEST TEST");

            var req = new HeaderCollection();

            req.AddItem("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9");

            var resp = new HeaderCollection();

            resp.AddItem("Content-Type", "text/html; charset=UTF-8");
            resp.AddItem("Content-Length", "14");

            var argsTest = new FetchCompleteEventArgs(lnk, bytes, req, resp);

            using var ms = new MemoryStream();
            FetchCompleteEventArgs.SaveFetchResult(argsTest, ms);
            ms.Position = 0;

            var argsLoaded = FetchCompleteEventArgs.LoadFetchResult(ms);

            checkEqual(argsTest, argsLoaded);
        }
Exemplo n.º 4
0
        public void Core_HeaderTests_HttpCtor()
        {
            string[] lines =
            {
                "Content-Type: text/html; charset=UTF-8",
                "Referer: http://quotes.toscrape.com/",
            };
            string[] keys =
            {
                "Content-Type",
                "Referer",
            };
            var hdr = new HeaderCollection(lines);

            testHeader(hdr);
            Assert.Equal(keys, hdr.AllKeys);

            hdr.AddItem("Accept", "text/html,application/xhtml+xml");
            Assert.Equal(3, hdr.Count);
            Assert.Equal("text/html,application/xhtml+xml", hdr["Accept"]);
        }
 /// <summary>
 /// Adds AddBaseRequestHeaders() then a Chrome Linux X11 x64 UA
 /// </summary>
 /// <param name="Header">Headers reference to add to</param>
 public static void AddChromeLinuxRequestHeaders(this HeaderCollection Header)
 {
     AddBaseRequestHeaders(Header);
     Header.AddItem("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.103 Safari/537.36");
 }
 /// <summary>
 /// Adds AddBaseRequestHeaders() then a Chrome Windows10 UA
 /// </summary>
 /// <param name="Header">Headers reference to add to</param>
 public static void AddChromeW10RequestHeaders(this HeaderCollection Header)
 {
     AddBaseRequestHeaders(Header);
     Header.AddItem("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.103 Safari/537.36");
 }
 /// <summary>
 /// Adds AddBaseRequestHeaders() then a firefox UA
 /// </summary>
 /// <param name="Header">Headers reference to add to</param>
 public static void AddFirefoxRequestHeaders(this HeaderCollection Header)
 {
     AddBaseRequestHeaders(Header);
     Header.AddItem("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0");
 }