Created
February 1, 2024 05:23
-
-
Save xeioex/f3ceec948833c254dfb51bee4b7e48eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
error_log /dev/stdout info; | |
daemon off; | |
master_process off; | |
#worker_processes 1; | |
events { } | |
http { | |
js_import main from fetch.js; | |
resolver 1.1.1.1; | |
server { | |
listen 8000; | |
location / { | |
js_content main.fetch; | |
} | |
} | |
server { | |
listen 8001; | |
location / { | |
js_content main.reply; | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function fetch(r) { | |
let reply = await ngx.fetch("http://127.0.0.1:8001/", | |
{ headers: { 'x-ms': "a", 'foo': 'xxx', 'Content-Length': "0" } }) | |
let body = await reply.text(); | |
r.return(200, body); | |
} | |
function reply(r) { | |
let body = [njs.version, '\n']; | |
r.rawHeadersIn.forEach((header) => { | |
body.push(`${header[0]}: ${header[1]}\n`); | |
}); | |
r.return(200, body.join('')); | |
} | |
export default { fetch, reply }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment