hono 1.2.0 → 1.2.1
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/README.md +1 -1
- package/dist/context.d.ts +3 -0
- package/dist/context.js +7 -0
- package/dist/middleware/basic-auth/index.js +7 -8
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/context.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export declare class Context<RequestParamKeyType = string, E = Env> {
|
|
|
13
13
|
private _statusText;
|
|
14
14
|
private _pretty;
|
|
15
15
|
private _prettySpace;
|
|
16
|
+
private _map;
|
|
16
17
|
render: (template: string, params?: object, options?: object) => Promise<Response>;
|
|
17
18
|
notFound: () => Response | Promise<Response>;
|
|
18
19
|
constructor(req: Request<RequestParamKeyType>, opts?: {
|
|
@@ -23,6 +24,8 @@ export declare class Context<RequestParamKeyType = string, E = Env> {
|
|
|
23
24
|
private initRequest;
|
|
24
25
|
header(name: string, value: string): void;
|
|
25
26
|
status(status: StatusCode): void;
|
|
27
|
+
set(key: string, value: any): void;
|
|
28
|
+
get(key: string): any;
|
|
26
29
|
pretty(prettyJSON: boolean, space?: number): void;
|
|
27
30
|
newResponse(data: Data, init?: ResponseInit): Response;
|
|
28
31
|
body(data: Data, status?: StatusCode, headers?: Headers): Response;
|
package/dist/context.js
CHANGED
|
@@ -12,6 +12,7 @@ class Context {
|
|
|
12
12
|
this._pretty = false;
|
|
13
13
|
this._prettySpace = 2;
|
|
14
14
|
this.req = this.initRequest(req);
|
|
15
|
+
this._map = {};
|
|
15
16
|
Object.assign(this, opts);
|
|
16
17
|
}
|
|
17
18
|
initRequest(req) {
|
|
@@ -34,6 +35,12 @@ class Context {
|
|
|
34
35
|
this._status = status;
|
|
35
36
|
this._statusText = (0, http_status_1.getStatusText)(status);
|
|
36
37
|
}
|
|
38
|
+
set(key, value) {
|
|
39
|
+
this._map[key] = value;
|
|
40
|
+
}
|
|
41
|
+
get(key) {
|
|
42
|
+
return this._map[key];
|
|
43
|
+
}
|
|
37
44
|
pretty(prettyJSON, space = 2) {
|
|
38
45
|
this._pretty = prettyJSON;
|
|
39
46
|
this._prettySpace = space;
|
|
@@ -42,17 +42,16 @@ const basicAuth = (options, ...users) => {
|
|
|
42
42
|
if (usernameEqual && passwordEqual) {
|
|
43
43
|
// Authorized OK
|
|
44
44
|
await next();
|
|
45
|
+
return;
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
});
|
|
55
|
-
}
|
|
49
|
+
ctx.res = new Response('Unauthorized', {
|
|
50
|
+
status: 401,
|
|
51
|
+
headers: {
|
|
52
|
+
'WWW-Authenticate': 'Basic realm="' + options.realm.replace(/"/g, '\\"') + '"',
|
|
53
|
+
},
|
|
54
|
+
});
|
|
56
55
|
};
|
|
57
56
|
};
|
|
58
57
|
exports.basicAuth = basicAuth;
|