Mercurial > hg > nginx-tests
diff stream_js_fetch.t @ 1784:898598722ad4
Tests: improved stream fetch test with async callbacks.
author | Dmitry Volyntsev <xeioex@nginx.com> |
---|---|
date | Tue, 23 Aug 2022 19:40:05 -0700 |
parents | 6b6a496ac984 |
children | 2c08bfffe112 |
line wrap: on
line diff
--- a/stream_js_fetch.t Thu Aug 04 09:41:44 2022 -0700 +++ b/stream_js_fetch.t Tue Aug 23 19:40:05 2022 -0700 @@ -85,14 +85,17 @@ function preread_verify(s) { var collect = Buffer.from([]); - s.on('upstream', function (data, flags) { + s.on('upstream', async function (data, flags) { collect = Buffer.concat([collect, data]); if (collect.length >= 4 && collect.readUInt16BE(0) == 0xabcd) { s.off('upstream'); - ngx.fetch('http://127.0.0.1:$p/validate', - {body: collect.slice(2,4), headers: {Host:'aaa'}}) - .then(reply => (reply.status == 200) ? s.done(): s.deny()) + + let reply = await ngx.fetch('http://127.0.0.1:$p/validate', + {body: collect.slice(2,4), + headers: {Host:'aaa'}}); + + (reply.status == 200) ? s.done(): s.deny(); } else if (collect.length) { s.deny();