This commit is contained in:
Redkale
2022-06-28 12:08:03 +08:00
parent 7f22eca8dc
commit ba618ceba0
2 changed files with 16 additions and 16 deletions

View File

@@ -118,7 +118,7 @@ public class HttpRequest extends Request<HttpContext> {
protected byte[] queryBytes; protected byte[] queryBytes;
protected String newsessionid; protected String newSessionid;
protected final Map<String, String> params = new HashMap<>(); protected final Map<String, String> params = new HashMap<>();
@@ -789,7 +789,7 @@ public class HttpRequest extends Request<HttpContext> {
this.respConvertType = null; this.respConvertType = null;
this.headers.clear(); this.headers.clear();
//其他 //其他
this.newsessionid = null; this.newSessionid = null;
this.method = null; this.method = null;
this.getmethod = false; this.getmethod = false;
this.protocol = null; this.protocol = null;
@@ -1278,16 +1278,16 @@ public class HttpRequest extends Request<HttpContext> {
/** /**
* 获取sessionid * 获取sessionid
* *
* @param create 无sessionid是否自动创建 * @param autoCreate 无sessionid是否自动创建
* *
* @return sessionid * @return sessionid
*/ */
@ConvertDisabled @ConvertDisabled
public String getSessionid(boolean create) { public String getSessionid(boolean autoCreate) {
String sessionid = getCookie(SESSIONID_NAME, null); String sessionid = getCookie(SESSIONID_NAME, null);
if (create && (sessionid == null || sessionid.isEmpty())) { if (autoCreate && (sessionid == null || sessionid.isEmpty())) {
sessionid = context.createSessionid(); sessionid = context.createSessionid();
this.newsessionid = sessionid; this.newSessionid = sessionid;
} }
return sessionid; return sessionid;
} }
@@ -1298,27 +1298,27 @@ public class HttpRequest extends Request<HttpContext> {
* @return 新的sessionid值 * @return 新的sessionid值
*/ */
public String changeSessionid() { public String changeSessionid() {
this.newsessionid = context.createSessionid(); this.newSessionid = context.createSessionid();
return newsessionid; return newSessionid;
} }
/** /**
* 指定值更新sessionid * 指定值更新sessionid
* *
* @param newsessionid 新sessionid值 * @param newSessionid 新sessionid值
* *
* @return 新的sessionid值 * @return 新的sessionid值
*/ */
public String changeSessionid(String newsessionid) { public String changeSessionid(String newSessionid) {
this.newsessionid = newsessionid == null ? context.createSessionid() : newsessionid.trim(); this.newSessionid = newSessionid == null ? context.createSessionid() : newSessionid.trim();
return newsessionid; return newSessionid;
} }
/** /**
* 使sessionid失效 * 使sessionid失效
*/ */
public void invalidateSession() { public void invalidateSession() {
this.newsessionid = ""; //为空表示删除sessionid this.newSessionid = ""; //为空表示删除sessionid
} }
/** /**

View File

@@ -1084,7 +1084,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
for (Entry<String> en : this.header.getStringEntrys()) { for (Entry<String> en : this.header.getStringEntrys()) {
headerArray.put((en.name + ": " + en.getValue() + "\r\n").getBytes()); headerArray.put((en.name + ": " + en.getValue() + "\r\n").getBytes());
} }
if (request.newsessionid != null) { if (request.newSessionid != null) {
String domain = defaultCookie == null ? null : defaultCookie.getDomain(); String domain = defaultCookie == null ? null : defaultCookie.getDomain();
if (domain == null || domain.isEmpty()) { if (domain == null || domain.isEmpty()) {
domain = ""; domain = "";
@@ -1093,10 +1093,10 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
} }
String path = defaultCookie == null ? null : defaultCookie.getPath(); String path = defaultCookie == null ? null : defaultCookie.getPath();
if (path == null || path.isEmpty()) path = "/"; if (path == null || path.isEmpty()) path = "/";
if (request.newsessionid.isEmpty()) { if (request.newSessionid.isEmpty()) {
headerArray.put(("Set-Cookie: " + HttpRequest.SESSIONID_NAME + "=; " + domain + "Path=/; Max-Age=0; HttpOnly\r\n").getBytes()); headerArray.put(("Set-Cookie: " + HttpRequest.SESSIONID_NAME + "=; " + domain + "Path=/; Max-Age=0; HttpOnly\r\n").getBytes());
} else { } else {
headerArray.put(("Set-Cookie: " + HttpRequest.SESSIONID_NAME + "=" + request.newsessionid + "; " + domain + "Path=/; HttpOnly\r\n").getBytes()); headerArray.put(("Set-Cookie: " + HttpRequest.SESSIONID_NAME + "=" + request.newSessionid + "; " + domain + "Path=/; HttpOnly\r\n").getBytes());
} }
} }
if (this.cookies != null) { if (this.cookies != null) {