Mercurial > hg > nginx-tests
changeset 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 | 95ba1e704b7b |
children | 2c08bfffe112 |
files | stream_js_fetch.t |
diffstat | 1 files changed, 7 insertions(+), 4 deletions(-) [+] |
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();