@reykjavik/webtools 0.1.27 → 0.1.28
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/CHANGELOG.md +7 -0
- package/README.md +2 -2
- package/esm/http.d.ts +2 -2
- package/esm/http.js +3 -9
- package/http.d.ts +2 -2
- package/http.js +3 -9
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -112,10 +112,10 @@ codes, are also available:
|
|
|
112
112
|
### `cacheControl` helper
|
|
113
113
|
|
|
114
114
|
**Syntax:**
|
|
115
|
-
`cacheConrol(response: ServerResponse | { res: ServerResponse }, ttlCfg: TTLConfig, eTag?: string|number): void`
|
|
115
|
+
`cacheConrol(response: ServerResponse | Response | Map<string, string> | { res: ServerResponse | Response }, ttlCfg: TTLConfig, eTag?: string|number): void`
|
|
116
116
|
|
|
117
117
|
Use this function to quickly set the `Cache-Control` header with a `max-age=`
|
|
118
|
-
on a HTTP response.
|
|
118
|
+
on a HTTP response (or a `Map` object representing response headers).
|
|
119
119
|
|
|
120
120
|
```js
|
|
121
121
|
import { cacheControl } from '@reykjavik/webtools/http';
|
package/esm/http.d.ts
CHANGED
|
@@ -168,7 +168,7 @@ type ServerResponseStub = Pick<ServerResponse, 'setHeader' | 'getHeader' | 'remo
|
|
|
168
168
|
headers?: Record<string, string | Array<string>>;
|
|
169
169
|
};
|
|
170
170
|
type ResponseStub = {
|
|
171
|
-
headers: Pick<Headers, 'set' | 'get' | 'delete'
|
|
171
|
+
headers: Pick<Headers, 'set' | 'get' | 'delete'>;
|
|
172
172
|
};
|
|
173
173
|
/**
|
|
174
174
|
* Use this function to quickly set the `Cache-Control` header with a `max-age=`
|
|
@@ -176,7 +176,7 @@ type ResponseStub = {
|
|
|
176
176
|
*
|
|
177
177
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#getcssbundleurl
|
|
178
178
|
*/
|
|
179
|
-
export declare const cacheControl: (response: ServerResponseStub | ResponseStub | {
|
|
179
|
+
export declare const cacheControl: (response: ServerResponseStub | ResponseStub | Map<string, string> | {
|
|
180
180
|
res: ServerResponseStub | ResponseStub;
|
|
181
181
|
}, ttlCfg: TTLConfig, eTag?: string | number) => void;
|
|
182
182
|
export {};
|
package/esm/http.js
CHANGED
|
@@ -147,6 +147,9 @@ export const toSec = (ttl) => {
|
|
|
147
147
|
return Math.max(0, Math.round(ttl)) || 0;
|
|
148
148
|
};
|
|
149
149
|
const toRespnseStubHeaders = (response) => {
|
|
150
|
+
if (response instanceof Map) {
|
|
151
|
+
return response;
|
|
152
|
+
}
|
|
150
153
|
if ('headers' in response && !('setHeader' in response)) {
|
|
151
154
|
return response.headers;
|
|
152
155
|
}
|
|
@@ -159,15 +162,6 @@ const toRespnseStubHeaders = (response) => {
|
|
|
159
162
|
return val != null ? `${val}` : null;
|
|
160
163
|
},
|
|
161
164
|
set: (name, value) => response.setHeader(name, value),
|
|
162
|
-
append: (name, value) => {
|
|
163
|
-
const existing = response.getHeader(name);
|
|
164
|
-
if (existing) {
|
|
165
|
-
response.setHeader(name, `${existing}, ${value}`);
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
response.setHeader(name, value);
|
|
169
|
-
}
|
|
170
|
-
},
|
|
171
165
|
delete: (name) => response.removeHeader(name),
|
|
172
166
|
};
|
|
173
167
|
};
|
package/http.d.ts
CHANGED
|
@@ -168,7 +168,7 @@ type ServerResponseStub = Pick<ServerResponse, 'setHeader' | 'getHeader' | 'remo
|
|
|
168
168
|
headers?: Record<string, string | Array<string>>;
|
|
169
169
|
};
|
|
170
170
|
type ResponseStub = {
|
|
171
|
-
headers: Pick<Headers, 'set' | 'get' | 'delete'
|
|
171
|
+
headers: Pick<Headers, 'set' | 'get' | 'delete'>;
|
|
172
172
|
};
|
|
173
173
|
/**
|
|
174
174
|
* Use this function to quickly set the `Cache-Control` header with a `max-age=`
|
|
@@ -176,7 +176,7 @@ type ResponseStub = {
|
|
|
176
176
|
*
|
|
177
177
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#getcssbundleurl
|
|
178
178
|
*/
|
|
179
|
-
export declare const cacheControl: (response: ServerResponseStub | ResponseStub | {
|
|
179
|
+
export declare const cacheControl: (response: ServerResponseStub | ResponseStub | Map<string, string> | {
|
|
180
180
|
res: ServerResponseStub | ResponseStub;
|
|
181
181
|
}, ttlCfg: TTLConfig, eTag?: string | number) => void;
|
|
182
182
|
export {};
|
package/http.js
CHANGED
|
@@ -152,6 +152,9 @@ const toSec = (ttl) => {
|
|
|
152
152
|
};
|
|
153
153
|
exports.toSec = toSec;
|
|
154
154
|
const toRespnseStubHeaders = (response) => {
|
|
155
|
+
if (response instanceof Map) {
|
|
156
|
+
return response;
|
|
157
|
+
}
|
|
155
158
|
if ('headers' in response && !('setHeader' in response)) {
|
|
156
159
|
return response.headers;
|
|
157
160
|
}
|
|
@@ -164,15 +167,6 @@ const toRespnseStubHeaders = (response) => {
|
|
|
164
167
|
return val != null ? `${val}` : null;
|
|
165
168
|
},
|
|
166
169
|
set: (name, value) => response.setHeader(name, value),
|
|
167
|
-
append: (name, value) => {
|
|
168
|
-
const existing = response.getHeader(name);
|
|
169
|
-
if (existing) {
|
|
170
|
-
response.setHeader(name, `${existing}, ${value}`);
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
response.setHeader(name, value);
|
|
174
|
-
}
|
|
175
|
-
},
|
|
176
170
|
delete: (name) => response.removeHeader(name),
|
|
177
171
|
};
|
|
178
172
|
};
|
package/package.json
CHANGED