seanmorris / php-wasm

PHP in Browser, powered by WebAssembly.
https://php-wasm.seanmorr.is/
Apache License 2.0
784 stars 41 forks source link

Header values #69

Open maxmcd opened 3 weeks ago

maxmcd commented 3 weeks ago

Hello, how do I retrieve header values that are set in the script?

const { PhpWeb } = await import("https://cdn.jsdelivr.net/npm/php-wasm/PhpWeb.mjs");
const php = new PhpWeb({ stdout: (x: any) => console.log("out", x), stderr: (x: any) => console.log("err", x) });

let logs: any[] = [];
php.addEventListener("output", (event: any) => logs.push(...event.detail));
const script = "<?php header('Content-Type: image/jpeg'); echo \"Hello, world!\"; ";
const exitCode = await php.run(script);
console.log({ script, exitCode, logs });

I can't seem to figure out how to grab the Content-Type header. Thanks!

seanmorris commented 4 days ago

That WOULD come in through the $http_response_header variable, which PHP sets automatically for a given HTTP request. That is being implemented right now, and should be released soon