Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Response.AddHeader("Last-Modified", DateTime.Now.ToString("U", DateTimeFormatInfo.InvariantInfo));
            DateTime IfModifiedSince;

            if (DateTime.TryParse(this.Request.Headers.Get("If-Modified-Since"), out IfModifiedSince))
            {
                if ((DateTime.Now - IfModifiedSince.AddHours(8)).Seconds < 10)
                {
                    Response.Status     = "304 Not Modified";
                    Response.StatusCode = 304;
                    return;
                }
            }
            Thread.Sleep(1000);
        }
        public override int GetHashCode()
        {
            var hash = HashSeed;

            hash = hash * HashFactor + typeof(IndexesActivityDelegate <TImageType>).GetHashCode();

            if (MusicFolderId != null)
            {
                hash = hash * HashFactor + MusicFolderId.GetHashCode();
            }

            if (IfModifiedSince != null)
            {
                hash = hash * HashFactor + IfModifiedSince.GetHashCode();
            }

            return(hash);
        }
Ejemplo n.º 3
0
        public IRequestHeader Parse(System.Net.Http.Headers.HttpRequestHeaders HttpRequestHeaders)
        {
            IEnumerable <string> IfNoneExist;

            if (HttpRequestHeaders.TryGetValues(_IfNoneExistHeader, out IfNoneExist))
            {
                this.IfNoneExist = IfNoneExist.FirstOrDefault();
            }

            IEnumerable <string> IfModifiedSince;

            if (HttpRequestHeaders.TryGetValues(_IfModifiedSinceHeader, out IfModifiedSince))
            {
                this.IfModifiedSince = IfModifiedSince.FirstOrDefault();
            }

            IEnumerable <string> IfNoneMatchHeader;

            if (HttpRequestHeaders.TryGetValues(_IfNoneMatchHeader, out IfNoneMatchHeader))
            {
                this.IfNoneMatch = IfNoneMatchHeader.FirstOrDefault();
            }

            IEnumerable <string> IfMatchHeader;

            if (HttpRequestHeaders.TryGetValues(_IfMatchHeader, out IfMatchHeader))
            {
                this.IfMatch = IfMatchHeader.FirstOrDefault();
            }

            IEnumerable <string> PreferHeader;

            if (HttpRequestHeaders.TryGetValues(_PreferHeader, out PreferHeader))
            {
                this.Prefer.Set(PreferHeader.FirstOrDefault());
            }

            return(this);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Get a hash code for the HttpAccessConditions.
 /// </summary>
 /// <returns>Hash code for the HttpAccessConditions.</returns>
 public override int GetHashCode()
 => IfModifiedSince.GetHashCode()
 ^ IfUnmodifiedSince.GetHashCode()
 ^ IfMatch.GetHashCode()
 ^ IfNoneMatch.GetHashCode()
 ;
Ejemplo n.º 5
0
        private void PostProcessHeaders()
        {
            if (HttpVersion == "1.1" && Host == null)
            {
                RequestError("400", "HTTP/1.1 requests must include Host header");
                return;
            }

            if (Client.Server.RequireAuthentication && Server.Authenticator.Authenticate(Username, Password) == false)
            {
                Response.SetHeader("WWW-Authenticate", "Basic realm=\"" + Client.Server.AuthenticateRealm + "\"");
                RequestError("401", StatusCodes.GetDescription("401"));
                return;
            }

            try {
                // Try parsing a relative URI
                //uri = new Uri(client.server.ServerUri, requestUri);
                Uri = Client.Server.GetRelUri(requestUri);
            }
            catch {
                try {
                    // Try parsing an absolute URI
                    //uri = new Uri(requestUri);
                    Uri = Client.Server.GetAbsUri(requestUri);
                }
                catch (UriFormatException) {
                    RequestError("400", "Invalid URI");
                    return;
                }
                catch (IndexOutOfRangeException) // System.Uri in .NET 1.1 throws this exception in certain cases
                {
                    RequestError("400", "Invalid URI");
                    return;
                }
            }

            if (Host != null)
            {
                Uri = Client.Server.GetHostUri(Host, requestUri);
            }

            // Try to determine the time difference between the client and this computer; adjust ifModifiedSince and ifUnmodifiedSince accordingly
            if (Date != DateTime.MinValue)
            {
                if (IfModifiedSince != DateTime.MinValue)
                {
                    IfModifiedSince = IfModifiedSince.Add(DateTime.UtcNow.Subtract(Date));
                }
                if (IfUnmodifiedSince != DateTime.MinValue)
                {
                    IfUnmodifiedSince = IfUnmodifiedSince.Add(DateTime.UtcNow.Subtract(Date));
                }
            }

            if (Method == "POST")
            {
                if (ContentLength == long.MinValue)
                {
                    RequestError("411", StatusCodes.GetDescription("411"));
                    return;
                }
                Mode = DataMode.Binary;
            }
            else
            {
                IsRequestFinished = true;
            }
        }