Ejemplo n.º 1
0
        /// <summary>Handles a CORS request that violates specification.</summary>
        /// <param name="request">
        /// The
        /// <see cref="Javax.Servlet.Http.IHttpServletRequest"/>
        /// object.
        /// </param>
        /// <param name="response">
        /// The
        /// <see cref="Javax.Servlet.Http.IHttpServletResponse"/>
        /// object.
        /// </param>
        /// <param name="filterChain">
        /// The
        /// <see cref="Javax.Servlet.IFilterChain"/>
        /// object.
        /// </param>
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="Javax.Servlet.ServletException"/>
        public void HandleInvalidCORS(IHttpServletRequest request, IHttpServletResponse response, IFilterChain filterChain)
        {
            string origin = request.GetHeader(Edu.Stanford.Nlp.Naturalli.Demo.CORSFilter.RequestHeaderOrigin);
            string method = request.GetMethod();
            string accessControlRequestHeaders = request.GetHeader(RequestHeaderAccessControlRequestHeaders);
            string message = "Invalid CORS request; Origin=" + origin + ";Method=" + method;

            if (accessControlRequestHeaders != null)
            {
                message = message + ";Access-Control-Request-Headers=" + accessControlRequestHeaders;
            }
            response.SetContentType("text/plain");
            response.SetStatus(HttpServletResponseConstants.ScForbidden);
            response.ResetBuffer();
            Log(message);
        }