-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathczldAPIRequest.js
33 lines (33 loc) · 895 Bytes
/
czldAPIRequest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function handler(event) {
let r = event.request,
m = r.method,
c = event.context;
try {
if (m !== 'PUT') {
throw new Error('Unsupported HTTP Method');
}
if (!r.querystring['s'] || !r.querystring['s'].value) {
throw new Error('Missing s query parameter');
}
if (
!r.headers['content-length'] ||
!r.headers['content-length'].value ||
'0' !== r.headers['content-length'].value
) {
throw new Error('Content-Length header must be 0');
}
if (r.querystring['s'].value.length > 1800) {
throw new Error('s query parameter exceeds max length');
}
r.uri = `/r/${c.requestId}`;
r.headers['x-amz-meta-s'] = { value: r.querystring['s'].value };
r.querystring = '';
return r;
} catch (e) {
return {
statusCode: 400,
statusDescription: 'Bad Request',
body: e.message,
};
}
}