Skip to content

Commit 84b0d64

Browse files
committed
[enh] rewriting stream/auth_request with an async callback
1 parent 667d066 commit 84b0d64

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

‎README.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,14 +1338,16 @@ example.js:
13381338
function preread_verify(s) {
13391339
var collect = '';
13401340
1341-
s.on('upload', function (data, flags) {
1341+
s.on('upload', async function (data, flags) {
13421342
collect += data;
13431343
13441344
if (collect.length >= 5 && collect.startsWith('MAGiK')) {
13451345
s.off('upload');
1346-
ngx.fetch('http://127.0.0.1:8080/validate',
1347-
{body: collect.slice(5,7), headers: {Host:'aaa'}})
1348-
.then(reply => (reply.status == 200) ? s.done(): s.deny())
1346+
let reply = ngx.fetch('http://127.0.0.1:8080/validate',
1347+
{body: collect.slice(5,7),
1348+
headers: {Host:'aaa'}});
1349+
1350+
(reply.status == 200) ? s.done(): s.deny();
13491351
13501352
} else if (collect.length) {
13511353
s.deny();

‎njs/stream/auth_request.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
function preread_verify(s) {
22
var collect = '';
33

4-
s.on('upload', function (data, flags) {
4+
s.on('upload', async function (data, flags) {
55
collect += data;
66

77
if (collect.length >= 5 && collect.startsWith('MAGiK')) {
88
s.off('upload');
9-
ngx.fetch('http://127.0.0.1:8080/validate',
10-
{body: collect.slice(5,7), headers: {Host:'aaa'}})
11-
.then(reply => (reply.status == 200) ? s.done(): s.deny())
9+
10+
let reply = await ngx.fetch('http://127.0.0.1:8080/validate',
11+
{body: collect.slice(5,7),
12+
headers: {Host:'aaa'}});
13+
14+
(reply.status == 200) ? s.done(): s.deny();
1215

1316
} else if (collect.length) {
1417
s.deny();

0 commit comments

Comments
 (0)