Merge pull request #26478 from weixsun

* pr/26478:
  Update copyright year of changed files
  Polish AbstractServletWebServerFactory

Closes gh-26478
pull/26586/head
Stephane Nicoll 4 years ago
commit 81d1c2e76d

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,6 +19,7 @@ package org.springframework.boot.web.servlet.server;
import java.io.File; import java.io.File;
import java.net.URL; import java.net.URL;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.time.Duration;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -37,6 +38,7 @@ import javax.servlet.SessionCookieConfig;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.boot.context.properties.PropertyMapper;
import org.springframework.boot.web.server.AbstractConfigurableWebServerFactory; import org.springframework.boot.web.server.AbstractConfigurableWebServerFactory;
import org.springframework.boot.web.server.MimeMappings; import org.springframework.boot.web.server.MimeMappings;
import org.springframework.boot.web.servlet.ServletContextInitializer; import org.springframework.boot.web.servlet.ServletContextInitializer;
@ -317,27 +319,14 @@ public abstract class AbstractServletWebServerFactory extends AbstractConfigurab
private void configureSessionCookie(SessionCookieConfig config) { private void configureSessionCookie(SessionCookieConfig config) {
Session.Cookie cookie = this.session.getCookie(); Session.Cookie cookie = this.session.getCookie();
if (cookie.getName() != null) { PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
config.setName(cookie.getName()); map.from(cookie::getName).to(config::setName);
} map.from(cookie::getDomain).to(config::setDomain);
if (cookie.getDomain() != null) { map.from(cookie::getPath).to(config::setPath);
config.setDomain(cookie.getDomain()); map.from(cookie::getComment).to(config::setComment);
} map.from(cookie::getHttpOnly).to(config::setHttpOnly);
if (cookie.getPath() != null) { map.from(cookie::getSecure).to(config::setSecure);
config.setPath(cookie.getPath()); map.from(cookie::getMaxAge).asInt(Duration::getSeconds).to(config::setMaxAge);
}
if (cookie.getComment() != null) {
config.setComment(cookie.getComment());
}
if (cookie.getHttpOnly() != null) {
config.setHttpOnly(cookie.getHttpOnly());
}
if (cookie.getSecure() != null) {
config.setSecure(cookie.getSecure());
}
if (cookie.getMaxAge() != null) {
config.setMaxAge((int) cookie.getMaxAge().getSeconds());
}
} }
private Set<javax.servlet.SessionTrackingMode> unwrap(Set<Session.SessionTrackingMode> modes) { private Set<javax.servlet.SessionTrackingMode> unwrap(Set<Session.SessionTrackingMode> modes) {

Loading…
Cancel
Save