public void TestCacheControlHeaderHashEquality()
        {
            // Arrange
            HttpCacheControlHeader a = new HttpCacheControlHeader();
            a.MaxAge = 3;
            a.MaxStaleAccept = true;
            a.MaxStaleValue = 392;
            a.MinFresh = 0;
            a.NoCache = false;
            a.NoTransform = true;
            a.OnlyIfCached = false;

            HttpCacheControlHeader b = new HttpCacheControlHeader();
            b.MaxAge = 3;
            b.MaxStaleAccept = true;
            b.MaxStaleValue = 392;
            b.MinFresh = 0;
            b.NoCache = false;
            b.NoTransform = true;
            b.OnlyIfCached = false;

            // Act
            int ha = a.GetHashCode();
            int hb = b.GetHashCode();

            // Assert
            Assert.AreEqual(ha, hb);
        }
        public void TestCacheControlHeaderParser()
        {
            // Arrange
            string accept = "max-age=3,max-stale=392,min-fresh=0,no-transform";
            HttpCacheControlHeader expected = new HttpCacheControlHeader();
            expected.MaxAge = 3;
            expected.MaxStaleAccept = true;
            expected.MaxStaleValue = 392;
            expected.MinFresh = 0;
            expected.NoCache = false;
            expected.NoTransform = true;
            expected.OnlyIfCached = false;

            // Act
            HttpCacheControlHeader header = HttpCacheControlHeader.Parse(accept);

            // Assert
            Assert.AreEqual(expected, header);
        }
        public void TestCacheControlHeaderEquality()
        {
            // Arrange
            HttpCacheControlHeader a = new HttpCacheControlHeader();
            a.MaxAge = 3;
            a.MaxStaleAccept = true;
            a.MaxStaleValue = 392;
            a.MinFresh = 0;
            a.NoCache = false;
            a.NoTransform = true;
            a.OnlyIfCached = false;

            HttpCacheControlHeader b = new HttpCacheControlHeader();
            b.MaxAge = 3;
            b.MaxStaleAccept = true;
            b.MaxStaleValue = 392;
            b.MinFresh = 0;
            b.NoCache = false;
            b.NoTransform = true;
            b.OnlyIfCached = false;

            // Assert
            Assert.AreEqual(a, b);
        }
Example #4
0
 public HttpHeaders()
 {
     CacheControl = new HttpCacheControlHeader();
     Connection = new HttpConnectionHeader();
 }
        /// <summary>
        /// Parse
        /// </summary>
        /// <param name="line">The Cache-Control parameter value string</param>
        /// <returns></returns>
        public static HttpCacheControlHeader Parse(string line)
        {
            HttpCacheControlHeader ret = new HttpCacheControlHeader();

            // split by comma
            string[] parts = line.Split(',').Select(s => s.Trim()).ToArray();
            for (int i = 0; i < parts.Length; i++)
            {
                // split by equals if there is
                string[] bits = parts[i].Split('=');
                if (StrComp(bits[0], "no-cache"))
                {
                    ret.NoCache = true;
                }
                else if (StrComp(bits[0], "no-store"))
                {
                    ret.NoStore = true;
                }
                else if (StrComp(bits[0], "max-age"))
                {
                    if (bits.Length > 1) ret.MaxAge = int.Parse(bits[1]);
                }
                else if (StrComp(bits[0], "max-stale"))
                {
                    ret.MaxStaleAccept = true;
                    if (bits.Length > 1) ret.MaxStaleValue = int.Parse(bits[1]);
                }
                else if (StrComp(bits[0], "min-fresh"))
                {
                    if (bits.Length > 1) ret.MinFresh = int.Parse(bits[1]);
                }
                else if (StrComp(bits[0], "no-transform"))
                {
                    ret.NoTransform = true;
                }
                else if (StrComp(bits[0], "only-if-cached"))
                {
                    ret.OnlyIfCached = true;
                }
            }

            return ret;
        }