Refine search
@Override public String getMethodValue() { return httpMethod.name(); } @Override
private static Set<HttpMethod> initAllowedHttpMethods(Set<String> declaredMethods) { Set<HttpMethod> result = new LinkedHashSet<>(declaredMethods.size()); if (declaredMethods.isEmpty()) { for (HttpMethod method : HttpMethod.values()) { if (method != HttpMethod.TRACE) { result.add(method); } } } else { for (String method : declaredMethods) { HttpMethod httpMethod = HttpMethod.valueOf(method); result.add(httpMethod); if (httpMethod == HttpMethod.GET) { result.add(HttpMethod.HEAD); } } result.add(HttpMethod.OPTIONS); } return result; }
@Override public String toString() { if (this.httpMethods.size() == 1) { return this.httpMethods.iterator().next().toString(); } else { return this.httpMethods.toString(); } } }
@Nullable private RequestMethodsRequestCondition matchRequestMethod(String httpMethodValue) { HttpMethod httpMethod = HttpMethod.resolve(httpMethodValue); if (httpMethod != null) { for (RequestMethod method : getMethods()) { if (httpMethod.matches(method.name())) { return new RequestMethodsRequestCondition(method); } } if (httpMethod == HttpMethod.HEAD && getMethods().contains(RequestMethod.GET)) { return GET_CONDITION; } } return null; }
/** * Returns {@code true} if the request is a valid CORS pre-flight one. */ public static boolean isPreFlightRequest(HttpServletRequest request) { return (isCorsRequest(request) && HttpMethod.OPTIONS.matches(request.getMethod()) && request.getHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD) != null); }
@Nullable private Object resolveArgument(Class<?> paramType, HttpServletRequest request) throws IOException { if (HttpSession.class.isAssignableFrom(paramType)) { HttpSession session = request.getSession(); if (session != null && !paramType.isInstance(session)) { throw new IllegalStateException( InputStream inputStream = request.getInputStream(); if (inputStream != null && !paramType.isInstance(inputStream)) { throw new IllegalStateException( Reader reader = request.getReader(); if (reader != null && !paramType.isInstance(reader)) { throw new IllegalStateException( return HttpMethod.resolve(request.getMethod());
@Override public boolean doesRequestMatch(HttpServletRequest request, PortResolver portResolver) { boolean result = (UrlUtils.buildFullRequestUrl(request).equals(redirectUrl)); String formRedirect = request.getParameter(FORM_REDIRECT_PARAMETER); if (!result && POST.name().equals(request.getMethod()) && hasText(formRedirect)) { //we received a form parameter result = formRedirect.equals(getRedirectUrl()); } return result; } }
protected boolean shouldSaveFormRedirectParameter(HttpServletRequest request) { String formRedirect = request.getParameter(FORM_REDIRECT_PARAMETER); if (!HttpMethod.POST.name().equals(request.getMethod())) { return false; } if (StringUtils.isEmpty(formRedirect)) { return false; } if (!UaaUrlUtils.uriHasMatchingHost(formRedirect, request.getServerName())) { return false; } if (hasSavedRequest(request)) { return false; } return POST.name().equals(request.getMethod()); }
@Override @Nullable public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { if (HttpMethod.OPTIONS.matches(request.getMethod())) { response.setHeader("Allow", getAllowHeader()); return null; } // Delegate to WebContentGenerator for checking and preparing. checkRequest(request); prepareResponse(response); // Execute handleRequestInternal in synchronized block if required. if (this.synchronizeOnSession) { HttpSession session = request.getSession(false); if (session != null) { Object mutex = WebUtils.getSessionMutex(session); synchronized (mutex) { return handleRequestInternal(request, response); } } } return handleRequestInternal(request, response); }
if (HttpMethod.OPTIONS.matches(request.getMethod())) { HttpOptionsHandler handler = new HttpOptionsHandler(methods); return new HandlerMethod(handler, HTTP_OPTIONS_HANDLE_METHOD); throw new HttpRequestMethodNotSupportedException(request.getMethod(), methods); Set<MediaType> mediaTypes = helper.getConsumableMediaTypes(); MediaType contentType = null; if (StringUtils.hasLength(request.getContentType())) { try { contentType = MediaType.parseMediaType(request.getContentType());
/** * Indicates whether the given request and response are eligible for ETag generation. * <p>The default implementation returns {@code true} if all conditions match: * <ul> * <li>response status codes in the {@code 2xx} series</li> * <li>request method is a GET</li> * <li>response Cache-Control header is not set or does not contain a "no-store" directive</li> * </ul> * @param request the HTTP request * @param response the HTTP response * @param responseStatusCode the HTTP response status code * @param inputStream the response body * @return {@code true} if eligible for ETag generation, {@code false} otherwise */ protected boolean isEligibleForEtag(HttpServletRequest request, HttpServletResponse response, int responseStatusCode, InputStream inputStream) { String method = request.getMethod(); if (responseStatusCode >= 200 && responseStatusCode < 300 && HttpMethod.GET.matches(method)) { String cacheControl = response.getHeader(HEADER_CACHE_CONTROL); return (cacheControl == null || !cacheControl.contains(DIRECTIVE_NO_STORE)); } return false; }
private static boolean isFormPost(HttpServletRequest request) { String contentType = request.getContentType(); return (contentType != null && contentType.contains(FORM_CONTENT_TYPE) && HttpMethod.POST.matches(request.getMethod())); }
@Test public void handleNoHandlerFoundException() throws Exception { ServletServerHttpRequest req = new ServletServerHttpRequest( new MockHttpServletRequest("GET","/resource")); NoHandlerFoundException ex = new NoHandlerFoundException(req.getMethod().name(), req.getServletRequest().getRequestURI(),req.getHeaders()); ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex); assertNotNull("No ModelAndView returned", mav); assertTrue("No Empty ModelAndView returned", mav.isEmpty()); assertEquals("Invalid status code", 404, response.getStatus()); }
@Test public void noHandlerFoundException() { ServletServerHttpRequest req = new ServletServerHttpRequest( new MockHttpServletRequest("GET","/resource")); Exception ex = new NoHandlerFoundException(req.getMethod().toString(), req.getServletRequest().getRequestURI(),req.getHeaders()); testException(ex); }
@Test public void enabled_no_whitelist_get() throws Exception { request.setMethod(GET.name()); filter.setStatusFile(statusFile); filter.setPermittedMethods(new HashSet<>(Arrays.asList(GET.toString()))); filter.doFilterInternal(request, response, chain); verify(chain, times(1)).doFilter(same(request), same(response)); }
/** * Determine whether this {@code HttpMethod} matches the given * method value. * @param method the method value as a String * @return {@code true} if it matches, {@code false} otherwise * @since 4.2.4 */ public boolean matches(String method) { return (this == resolve(method)); }
private ServerWebExchange getExchange(String method) throws URISyntaxException { return MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.valueOf(method), "/")); }