@Override public boolean checkNotModified(@Nullable String etag, Instant lastModified) { HttpStatus status = getResponse().getStatusCode(); if (this.notModified || (status != null && !HttpStatus.OK.equals(status))) { return this.notModified; if (validateIfUnmodifiedSince(lastModified)) { if (this.notModified) { getResponse().setStatusCode(HttpStatus.PRECONDITION_FAILED); boolean validated = validateIfNoneMatch(etag); if (!validated) { validateIfModifiedSince(lastModified); boolean isHttpGetOrHead = SAFE_METHODS.contains(getRequest().getMethod()); if (this.notModified) { getResponse().setStatusCode(isHttpGetOrHead ? HttpStatus.NOT_MODIFIED : HttpStatus.PRECONDITION_FAILED); if (lastModified.isAfter(Instant.EPOCH) && getResponseHeaders().getLastModified() == -1) { getResponseHeaders().setLastModified(lastModified.toEpochMilli()); if (StringUtils.hasLength(etag) && getResponseHeaders().getETag() == null) { getResponseHeaders().setETag(padEtagIfNecessary(etag));
protected ServerWebExchange createExchange(ServerHttpRequest request, ServerHttpResponse response) { return new DefaultServerWebExchange(request, response, this.sessionManager, getCodecConfigurer(), getLocaleContextResolver(), this.applicationContext); }
@Override public boolean checkNotModified(String etag) { return checkNotModified(etag, Instant.MIN); }
DefaultServerWebExchange(ServerHttpRequest request, ServerHttpResponse response, WebSessionManager sessionManager, ServerCodecConfigurer codecConfigurer, LocaleContextResolver localeContextResolver, @Nullable ApplicationContext applicationContext) { Assert.notNull(request, "'request' is required"); Assert.notNull(response, "'response' is required"); Assert.notNull(sessionManager, "'sessionManager' is required"); Assert.notNull(codecConfigurer, "'codecConfigurer' is required"); Assert.notNull(localeContextResolver, "'localeContextResolver' is required"); // Initialize before first call to getLogPrefix() this.attributes.put(ServerWebExchange.LOG_ID_ATTRIBUTE, request.getId()); this.request = request; this.response = response; this.sessionMono = sessionManager.getSession(this).cache(); this.localeContextResolver = localeContextResolver; this.formDataMono = initFormData(request, codecConfigurer, getLogPrefix()); this.multipartDataMono = initMultipartData(request, codecConfigurer, getLogPrefix()); this.applicationContext = applicationContext; }
ifNoneMatch = getRequestHeaders().getIfNoneMatch(); etag = padEtagIfNecessary(etag); if (etag.startsWith("W/")) { etag = etag.substring(2);
@Override public MockServerHttpResponse getResponse() { return (MockServerHttpResponse) super.getResponse(); }
DefaultServerWebExchange(ServerHttpRequest request, ServerHttpResponse response, WebSessionManager sessionManager, ServerCodecConfigurer codecConfigurer, LocaleContextResolver localeContextResolver, @Nullable ApplicationContext applicationContext) { Assert.notNull(request, "'request' is required"); Assert.notNull(response, "'response' is required"); Assert.notNull(sessionManager, "'sessionManager' is required"); Assert.notNull(codecConfigurer, "'codecConfigurer' is required"); Assert.notNull(localeContextResolver, "'localeContextResolver' is required"); this.request = request; this.response = response; this.sessionMono = sessionManager.getSession(this).cache(); this.localeContextResolver = localeContextResolver; this.formDataMono = initFormData(request, codecConfigurer); this.multipartDataMono = initMultipartData(request, codecConfigurer); this.applicationContext = applicationContext; }
private boolean validateIfModifiedSince(Instant lastModified) { if (lastModified.isBefore(Instant.EPOCH)) { return false; } long ifModifiedSince = getRequestHeaders().getIfModifiedSince(); if (ifModifiedSince == -1) { return false; } // We will perform this validation... this.notModified = ChronoUnit.SECONDS.between(lastModified, Instant.ofEpochMilli(ifModifiedSince)) >= 0; return true; }
private HttpHeaders getRequestHeaders() { return getRequest().getHeaders(); }
@Override public String getLogPrefix() { Object value = getAttribute(LOG_ID_ATTRIBUTE); if (this.logId != value) { this.logId = value; this.logPrefix = value != null ? "[" + value + "] " : ""; } return this.logPrefix; }
@Override public MockServerHttpResponse getResponse() { return (MockServerHttpResponse) super.getResponse(); }
DefaultServerWebExchange(ServerHttpRequest request, ServerHttpResponse response, WebSessionManager sessionManager, ServerCodecConfigurer codecConfigurer, LocaleContextResolver localeContextResolver, @Nullable ApplicationContext applicationContext) { Assert.notNull(request, "'request' is required"); Assert.notNull(response, "'response' is required"); Assert.notNull(sessionManager, "'sessionManager' is required"); Assert.notNull(codecConfigurer, "'codecConfigurer' is required"); Assert.notNull(localeContextResolver, "'localeContextResolver' is required"); // Initialize before first call to getLogPrefix() this.attributes.put(ServerWebExchange.LOG_ID_ATTRIBUTE, request.getId()); this.request = request; this.response = response; this.sessionMono = sessionManager.getSession(this).cache(); this.localeContextResolver = localeContextResolver; this.formDataMono = initFormData(request, codecConfigurer, getLogPrefix()); this.multipartDataMono = initMultipartData(request, codecConfigurer, getLogPrefix()); this.applicationContext = applicationContext; }
ifNoneMatch = getRequestHeaders().getIfNoneMatch(); etag = padEtagIfNecessary(etag); if (etag.startsWith("W/")) { etag = etag.substring(2);
private boolean validateIfUnmodifiedSince(Instant lastModified) { if (lastModified.isBefore(Instant.EPOCH)) { return false; } long ifUnmodifiedSince = getRequestHeaders().getIfUnmodifiedSince(); if (ifUnmodifiedSince == -1) { return false; } // We will perform this validation... Instant sinceInstant = Instant.ofEpochMilli(ifUnmodifiedSince); this.notModified = sinceInstant.isBefore(lastModified.truncatedTo(ChronoUnit.SECONDS)); return true; }
private HttpHeaders getRequestHeaders() { return getRequest().getHeaders(); }
@Override public String getLogPrefix() { Object value = getAttribute(LOG_ID_ATTRIBUTE); if (this.logId != value) { this.logId = value; this.logPrefix = value != null ? "[" + value + "] " : ""; } return this.logPrefix; }
@Override public boolean checkNotModified(@Nullable String etag, Instant lastModified) { HttpStatus status = getResponse().getStatusCode(); if (this.notModified || (status != null && !HttpStatus.OK.equals(status))) { return this.notModified; if (validateIfUnmodifiedSince(lastModified)) { if (this.notModified) { getResponse().setStatusCode(HttpStatus.PRECONDITION_FAILED); boolean validated = validateIfNoneMatch(etag); if (!validated) { validateIfModifiedSince(lastModified); boolean isHttpGetOrHead = SAFE_METHODS.contains(getRequest().getMethod()); if (this.notModified) { getResponse().setStatusCode(isHttpGetOrHead ? HttpStatus.NOT_MODIFIED : HttpStatus.PRECONDITION_FAILED); if (lastModified.isAfter(Instant.EPOCH) && getResponseHeaders().getLastModified() == -1) { getResponseHeaders().setLastModified(lastModified.toEpochMilli()); if (StringUtils.hasLength(etag) && getResponseHeaders().getETag() == null) { getResponseHeaders().setETag(padEtagIfNecessary(etag));
private HttpHeaders getResponseHeaders() { return getResponse().getHeaders(); }
DefaultServerWebExchange(ServerHttpRequest request, ServerHttpResponse response, WebSessionManager sessionManager, ServerCodecConfigurer codecConfigurer, LocaleContextResolver localeContextResolver, @Nullable ApplicationContext applicationContext) { Assert.notNull(request, "'request' is required"); Assert.notNull(response, "'response' is required"); Assert.notNull(sessionManager, "'sessionManager' is required"); Assert.notNull(codecConfigurer, "'codecConfigurer' is required"); Assert.notNull(localeContextResolver, "'localeContextResolver' is required"); // Initialize before first call to getLogPrefix() this.attributes.put(ServerWebExchange.LOG_ID_ATTRIBUTE, request.getId()); this.request = request; this.response = response; this.sessionMono = sessionManager.getSession(this).cache(); this.localeContextResolver = localeContextResolver; this.formDataMono = initFormData(request, codecConfigurer, getLogPrefix()); this.multipartDataMono = initMultipartData(request, codecConfigurer, getLogPrefix()); this.applicationContext = applicationContext; }
protected ServerWebExchange createExchange(ServerHttpRequest request, ServerHttpResponse response) { return new DefaultServerWebExchange(request, response, this.sessionManager, getCodecConfigurer(), getLocaleContextResolver(), this.applicationContext); }