@Nullable private HttpMethod getMethodToUse(ServerHttpRequest request, boolean isPreFlight) { return (isPreFlight ? request.getHeaders().getAccessControlRequestMethod() : request.getMethod()); }
@Nullable private HttpMethod getMethodToUse(ServerHttpRequest request, boolean isPreFlight) { return (isPreFlight ? request.getHeaders().getAccessControlRequestMethod() : request.getMethod()); }
@Override public void handle(ServerHttpRequest request, ServerHttpResponse response) throws IOException { if (request.getMethod() == HttpMethod.GET) { addNoCacheHeaders(response); if (checkOrigin(request, response)) { response.getHeaders().setContentType(new MediaType("application", "json", StandardCharsets.UTF_8)); String content = String.format( INFO_CONTENT, random.nextInt(), isSessionCookieNeeded(), isWebSocketEnabled()); response.getBody().write(content.getBytes()); } } else if (request.getMethod() == HttpMethod.OPTIONS) { if (checkOrigin(request, response)) { addCacheHeaders(response); response.setStatusCode(HttpStatus.NO_CONTENT); } } else { sendMethodNotAllowed(response, HttpMethod.GET, HttpMethod.OPTIONS); } } };
String requestInfo = (logger.isDebugEnabled() ? request.getMethod() + " " + request.getURI() : null);
@Override public void handle(ServerHttpRequest request, ServerHttpResponse response) throws IOException { if (request.getMethod() != HttpMethod.GET) { sendMethodNotAllowed(response, HttpMethod.GET); return; } String content = String.format(IFRAME_CONTENT, getSockJsClientLibraryUrl()); byte[] contentBytes = content.getBytes(StandardCharsets.UTF_8); StringBuilder builder = new StringBuilder("\"0"); DigestUtils.appendMd5DigestAsHex(contentBytes, builder); builder.append('"'); String etagValue = builder.toString(); List<String> ifNoneMatch = request.getHeaders().getIfNoneMatch(); if (!CollectionUtils.isEmpty(ifNoneMatch) && ifNoneMatch.get(0).equals(etagValue)) { response.setStatusCode(HttpStatus.NOT_MODIFIED); return; } response.getHeaders().setContentType(new MediaType("text", "html", StandardCharsets.UTF_8)); response.getHeaders().setContentLength(contentBytes.length); // No cache in order to check every time if IFrame are authorized addNoCacheHeaders(response); response.getHeaders().setETag(etagValue); response.getBody().write(contentBytes); } };
logger.debug(request.getMethod() + " " + request.getURI());
@Test public void getMethod() throws Exception { this.mockRequest.addFile(new MockMultipartFile("part", "", "", "content".getBytes("UTF-8"))); ServerHttpRequest request = new RequestPartServletServerHttpRequest(this.mockRequest, "part"); this.mockRequest.setMethod("POST"); assertEquals(HttpMethod.POST, request.getMethod()); }
request.getMethod(), request.getHeaders(), () -> BodyInserters.fromDataBuffers(DataBufferUtils.readInputStream(request::getBody,
/** * Returns whether the request is a PATCH request. * * @return */ public boolean isPatchRequest() { return request.getMethod().equals(HttpMethod.PATCH); }
/** * Returns whether the request is a PATCH request. * * @return */ public boolean isPatchRequest() { return request.getMethod().equals(HttpMethod.PATCH); }
@Nullable private HttpMethod getMethodToUse(ServerHttpRequest request, boolean isPreFlight) { return (isPreFlight ? request.getHeaders().getAccessControlRequestMethod() : request.getMethod()); }
@Nullable private HttpMethod getMethodToUse(ServerHttpRequest request, boolean isPreFlight) { return (isPreFlight ? request.getHeaders().getAccessControlRequestMethod() : request.getMethod()); }
throws Exception { log.info("Request received: {} {} - with headers: {}", request.getMethod(), request.getURI(), request.getHeaders());
@Override public void handle(ServerHttpRequest request, ServerHttpResponse response) throws IOException { if (request.getMethod() == HttpMethod.GET) { addNoCacheHeaders(response); if (checkOrigin(request, response)) { response.getHeaders().setContentType(new MediaType("application", "json", StandardCharsets.UTF_8)); String content = String.format( INFO_CONTENT, random.nextInt(), isSessionCookieNeeded(), isWebSocketEnabled()); response.getBody().write(content.getBytes()); } } else if (request.getMethod() == HttpMethod.OPTIONS) { if (checkOrigin(request, response)) { addCacheHeaders(response); response.setStatusCode(HttpStatus.NO_CONTENT); } } else { sendMethodNotAllowed(response, HttpMethod.GET, HttpMethod.OPTIONS); } } };
@Override public void handle(ServerHttpRequest request, ServerHttpResponse response) throws IOException { if (request.getMethod() == HttpMethod.GET) { addNoCacheHeaders(response); if (checkOrigin(request, response)) { response.getHeaders().setContentType(new MediaType("application", "json", StandardCharsets.UTF_8)); String content = String.format( INFO_CONTENT, random.nextInt(), isSessionCookieNeeded(), isWebSocketEnabled()); response.getBody().write(content.getBytes()); } } else if (request.getMethod() == HttpMethod.OPTIONS) { if (checkOrigin(request, response)) { addCacheHeaders(response); response.setStatusCode(HttpStatus.NO_CONTENT); } } else { sendMethodNotAllowed(response, HttpMethod.GET, HttpMethod.OPTIONS); } } };
@Override public void handle(ServerHttpRequest request, ServerHttpResponse response) throws IOException { if (request.getMethod() != HttpMethod.GET) { sendMethodNotAllowed(response, HttpMethod.GET); return; } String content = String.format(IFRAME_CONTENT, getSockJsClientLibraryUrl()); byte[] contentBytes = content.getBytes(StandardCharsets.UTF_8); StringBuilder builder = new StringBuilder("\"0"); DigestUtils.appendMd5DigestAsHex(contentBytes, builder); builder.append('"'); String etagValue = builder.toString(); List<String> ifNoneMatch = request.getHeaders().getIfNoneMatch(); if (!CollectionUtils.isEmpty(ifNoneMatch) && ifNoneMatch.get(0).equals(etagValue)) { response.setStatusCode(HttpStatus.NOT_MODIFIED); return; } response.getHeaders().setContentType(new MediaType("text", "html", StandardCharsets.UTF_8)); response.getHeaders().setContentLength(contentBytes.length); // No cache in order to check every time if IFrame are authorized addNoCacheHeaders(response); response.getHeaders().setETag(etagValue); response.getBody().write(contentBytes); } };
@Override public void handle(ServerHttpRequest request, ServerHttpResponse response) throws IOException { if (request.getMethod() != HttpMethod.GET) { sendMethodNotAllowed(response, HttpMethod.GET); return; } String content = String.format(IFRAME_CONTENT, getSockJsClientLibraryUrl()); byte[] contentBytes = content.getBytes(StandardCharsets.UTF_8); StringBuilder builder = new StringBuilder("\"0"); DigestUtils.appendMd5DigestAsHex(contentBytes, builder); builder.append('"'); String etagValue = builder.toString(); List<String> ifNoneMatch = request.getHeaders().getIfNoneMatch(); if (!CollectionUtils.isEmpty(ifNoneMatch) && ifNoneMatch.get(0).equals(etagValue)) { response.setStatusCode(HttpStatus.NOT_MODIFIED); return; } response.getHeaders().setContentType(new MediaType("text", "html", StandardCharsets.UTF_8)); response.getHeaders().setContentLength(contentBytes.length); // No cache in order to check every time if IFrame are authorized addNoCacheHeaders(response); response.getHeaders().setETag(etagValue); response.getBody().write(contentBytes); } };
logger.debug(request.getMethod() + " " + request.getURI());