@yumerijs/core 2.0.5 → 2.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server.js +56 -52
- package/dist/session.d.ts +1 -0
- package/dist/session.js +2 -0
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -118,34 +118,36 @@ class Server {
|
|
|
118
118
|
this.serveStaticFile(pathname, res);
|
|
119
119
|
}
|
|
120
120
|
else {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
121
|
+
if (!session.responseHandled) {
|
|
122
|
+
let head = session.head;
|
|
123
|
+
head['Set-Cookie'] = Object.entries(session.newCookie).map(([name, cookie]) => {
|
|
124
|
+
let cookieString = `${name}=${cookie.value}`;
|
|
125
|
+
if (cookie.options.expires) {
|
|
126
|
+
cookieString += `; Expires=${cookie.options.expires.toUTCString()}`;
|
|
127
|
+
}
|
|
128
|
+
if (cookie.options.path) {
|
|
129
|
+
cookieString += `; Path=${cookie.options.path}`;
|
|
130
|
+
}
|
|
131
|
+
if (cookie.options.domain) {
|
|
132
|
+
cookieString += `; Domain=${cookie.options.domain}`;
|
|
133
|
+
}
|
|
134
|
+
if (cookie.options.secure) {
|
|
135
|
+
cookieString += `; Secure`;
|
|
136
|
+
}
|
|
137
|
+
if (cookie.options.httpOnly) {
|
|
138
|
+
cookieString += `; HttpOnly`;
|
|
139
|
+
}
|
|
140
|
+
if (cookie.options.sameSite) {
|
|
141
|
+
cookieString += `; SameSite=${cookie.options.sameSite}`;
|
|
142
|
+
}
|
|
143
|
+
return cookieString;
|
|
144
|
+
});
|
|
145
|
+
if (this.enableCors) {
|
|
146
|
+
head['Access-Control-Allow-Origin'] = '*';
|
|
126
147
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
if (cookie.options.domain) {
|
|
131
|
-
cookieString += `; Domain=${cookie.options.domain}`;
|
|
132
|
-
}
|
|
133
|
-
if (cookie.options.secure) {
|
|
134
|
-
cookieString += `; Secure`;
|
|
135
|
-
}
|
|
136
|
-
if (cookie.options.httpOnly) {
|
|
137
|
-
cookieString += `; HttpOnly`;
|
|
138
|
-
}
|
|
139
|
-
if (cookie.options.sameSite) {
|
|
140
|
-
cookieString += `; SameSite=${cookie.options.sameSite}`;
|
|
141
|
-
}
|
|
142
|
-
return cookieString;
|
|
143
|
-
});
|
|
144
|
-
if (this.enableCors) {
|
|
145
|
-
head['Access-Control-Allow-Origin'] = '*';
|
|
148
|
+
res.writeHead(session.status ?? 200, head);
|
|
149
|
+
res.end(session.body);
|
|
146
150
|
}
|
|
147
|
-
res.writeHead(session.status ?? 200, head);
|
|
148
|
-
res.end(session.body);
|
|
149
151
|
}
|
|
150
152
|
}
|
|
151
153
|
else if (rootroute && rootroute.allowedMethods.includes(req.method ?? 'GET')) {
|
|
@@ -154,34 +156,36 @@ class Server {
|
|
|
154
156
|
this.serveStaticFile(pathname, res);
|
|
155
157
|
}
|
|
156
158
|
else {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
159
|
+
if (!session.responseHandled) {
|
|
160
|
+
let head = session.head;
|
|
161
|
+
head['Set-Cookie'] = Object.entries(session.newCookie).map(([name, cookie]) => {
|
|
162
|
+
let cookieString = `${name}=${cookie.value}`;
|
|
163
|
+
if (cookie.options.expires) {
|
|
164
|
+
cookieString += `; Expires=${cookie.options.expires.toUTCString()}`;
|
|
165
|
+
}
|
|
166
|
+
if (cookie.options.path) {
|
|
167
|
+
cookieString += `; Path=${cookie.options.path}`;
|
|
168
|
+
}
|
|
169
|
+
if (cookie.options.domain) {
|
|
170
|
+
cookieString += `; Domain=${cookie.options.domain}`;
|
|
171
|
+
}
|
|
172
|
+
if (cookie.options.secure) {
|
|
173
|
+
cookieString += `; Secure`;
|
|
174
|
+
}
|
|
175
|
+
if (cookie.options.httpOnly) {
|
|
176
|
+
cookieString += `; HttpOnly`;
|
|
177
|
+
}
|
|
178
|
+
if (cookie.options.sameSite) {
|
|
179
|
+
cookieString += `; SameSite=${cookie.options.sameSite}`;
|
|
180
|
+
}
|
|
181
|
+
return cookieString;
|
|
182
|
+
});
|
|
183
|
+
if (this.enableCors) {
|
|
184
|
+
head['Access-Control-Allow-Origin'] = '*';
|
|
162
185
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
if (cookie.options.domain) {
|
|
167
|
-
cookieString += `; Domain=${cookie.options.domain}`;
|
|
168
|
-
}
|
|
169
|
-
if (cookie.options.secure) {
|
|
170
|
-
cookieString += `; Secure`;
|
|
171
|
-
}
|
|
172
|
-
if (cookie.options.httpOnly) {
|
|
173
|
-
cookieString += `; HttpOnly`;
|
|
174
|
-
}
|
|
175
|
-
if (cookie.options.sameSite) {
|
|
176
|
-
cookieString += `; SameSite=${cookie.options.sameSite}`;
|
|
177
|
-
}
|
|
178
|
-
return cookieString;
|
|
179
|
-
});
|
|
180
|
-
if (this.enableCors) {
|
|
181
|
-
head['Access-Control-Allow-Origin'] = '*';
|
|
186
|
+
res.writeHead(session.status ?? 200, head);
|
|
187
|
+
res.end(session.body);
|
|
182
188
|
}
|
|
183
|
-
res.writeHead(session.status ?? 200, head);
|
|
184
|
-
res.end(session.body);
|
|
185
189
|
}
|
|
186
190
|
}
|
|
187
191
|
else {
|
package/dist/session.d.ts
CHANGED
package/dist/session.js
CHANGED
|
@@ -60,6 +60,7 @@ class Session {
|
|
|
60
60
|
protocol = 'http';
|
|
61
61
|
pathname;
|
|
62
62
|
languages;
|
|
63
|
+
responseHandled = false;
|
|
63
64
|
/**
|
|
64
65
|
* @constructor
|
|
65
66
|
* @param ip 用户IP
|
|
@@ -261,6 +262,7 @@ class Session {
|
|
|
261
262
|
return this.client.res.write(data);
|
|
262
263
|
}
|
|
263
264
|
endsession(message) {
|
|
265
|
+
this.responseHandled = true;
|
|
264
266
|
return this.client.res.end(message);
|
|
265
267
|
}
|
|
266
268
|
/**
|