Esempio n. 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void doFilter(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse, javax.servlet.FilterChain chain) throws java.io.IOException, javax.servlet.ServletException
        public override void DoFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain)
        {
            HttpServletRequest  request  = ( HttpServletRequest )servletRequest;
            HttpServletResponse response = ( HttpServletResponse )servletResponse;

            response.setHeader(ACCESS_CONTROL_ALLOW_ORIGIN, _accessControlAllowOrigin);
            if (!string.ReferenceEquals(_vary, null))
            {
                response.setHeader(VARY, _vary);
            }

            IEnumerator <string> requestMethodEnumeration = request.getHeaders(ACCESS_CONTROL_REQUEST_METHOD);

            if (requestMethodEnumeration != null)
            {
                while (requestMethodEnumeration.MoveNext())
                {
                    string requestMethod = requestMethodEnumeration.Current;
                    AddAllowedMethodIfValid(requestMethod, response);
                }
            }

            IEnumerator <string> requestHeaderEnumeration = request.getHeaders(ACCESS_CONTROL_REQUEST_HEADERS);

            if (requestHeaderEnumeration != null)
            {
                while (requestHeaderEnumeration.MoveNext())
                {
                    string requestHeader = requestHeaderEnumeration.Current;
                    AddAllowedHeaderIfValid(requestHeader, response);
                }
            }

            chain.doFilter(request, response);
        }
Esempio n. 2
0
        private static HttpServletRequest RequestMock(IList <string> accessControlRequestMethods, IList <string> accessControlRequestHeaders)
        {
            HttpServletRequest mock = mock(typeof(HttpServletRequest));

            when(mock.getHeaders(ACCESS_CONTROL_REQUEST_METHOD)).thenReturn(enumeration(accessControlRequestMethods));
            when(mock.getHeaders(ACCESS_CONTROL_REQUEST_HEADERS)).thenReturn(enumeration(accessControlRequestHeaders));
            return(mock);
        }
Esempio n. 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAttachNoHttpMethodsToAccessControlAllowMethodsWhenHeaderIsNull() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAttachNoHttpMethodsToAccessControlAllowMethodsWhenHeaderIsNull()
        {
            HttpServletRequest request = RequestMock();

            when(request.getHeaders(ACCESS_CONTROL_REQUEST_METHOD)).thenReturn(null);

            _filter.doFilter(request, _response, _chain);

            verify(_response, never()).addHeader(eq(ACCESS_CONTROL_ALLOW_METHODS), anyString());
        }