<p dir="auto">The "fetch" function does not allow to modify the "host" in the request header, resulting in the inability to implement the proxy request of the reverse proxy server.</p>
<p dir="auto">This can be done in nodejs.</p>
<p dir="auto">This is not possible in deno.</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import { serve } from &quot;https://deno.land/std@0.144.0/http/mod.ts&quot;;
import { assertEquals } from &quot;https://deno.land/std@0.144.0/testing/asserts.ts&quot;;

Deno.test(&quot;http-request-host&quot;, async () =&gt; {
    const ac = new AbortController();
    const { signal } = ac;
    const p = serve(async (req) =&gt; new Response(req.url), {
        signal,
        port: 5000,
    });
    const response = await fetch(&quot;http://127.0.0.1:5000/&quot;, {
        headers: { host: &quot;localhost.hello.world:9900&quot; },
    });
    const text = await response.text();
    assertEquals(text, &quot;http://localhost.hello.world:9900/&quot;);
    ac.abort();
    await p;
});
"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-kos">{</span> <span class="pl-s1">serve</span> <span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">"https://deno.land/std@0.144.0/http/mod.ts"</span><span class="pl-kos">;</span>
<span class="pl-k">import</span> <span class="pl-kos">{</span> <span class="pl-s1">assertEquals</span> <span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">"https://deno.land/std@0.144.0/testing/asserts.ts"</span><span class="pl-kos">;</span>

<span class="pl-smi">Deno</span><span class="pl-kos">.</span><span class="pl-en">test</span><span class="pl-kos">(</span><span class="pl-s">"http-request-host"</span><span class="pl-kos">,</span> <span class="pl-k">async</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-k">const</span> <span class="pl-s1">ac</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-smi">AbortController</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">const</span> <span class="pl-kos">{</span> signal <span class="pl-kos">}</span> <span class="pl-c1">=</span> <span class="pl-s1">ac</span><span class="pl-kos">;</span>
    <span class="pl-k">const</span> <span class="pl-s1">p</span> <span class="pl-c1">=</span> <span class="pl-en">serve</span><span class="pl-kos">(</span><span class="pl-k">async</span> <span class="pl-kos">(</span><span class="pl-s1">req</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-k">new</span> <span class="pl-smi">Response</span><span class="pl-kos">(</span><span class="pl-s1">req</span><span class="pl-kos">.</span><span class="pl-c1">url</span><span class="pl-kos">)</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>
        signal<span class="pl-kos">,</span>
        <span class="pl-c1">port</span>: <span class="pl-c1">5000</span><span class="pl-kos">,</span>
    <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">const</span> <span class="pl-s1">response</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-en">fetch</span><span class="pl-kos">(</span><span class="pl-s">"http://127.0.0.1:5000/"</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>
        <span class="pl-c1">headers</span>: <span class="pl-kos">{</span> <span class="pl-c1">host</span>: <span class="pl-s">"localhost.hello.world:9900"</span> <span class="pl-kos">}</span><span class="pl-kos">,</span>
    <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">const</span> <span class="pl-s1">text</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-s1">response</span><span class="pl-kos">.</span><span class="pl-en">text</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-en">assertEquals</span><span class="pl-kos">(</span><span class="pl-s1">text</span><span class="pl-kos">,</span> <span class="pl-s">"http://localhost.hello.world:9900/"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-s1">ac</span><span class="pl-kos">.</span><span class="pl-en">abort</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">await</span> <span class="pl-s1">p</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="

http-request-host ... FAILED (30ms)

 ERRORS

http-request-host =&gt; ./test.ts:4:6
error: AssertionError: Values are not equal:


    [Diff] Actual / Expected


-   http://127.0.0.1:5000/
+   http://localhost.hello.world:9900/


  throw new AssertionError(message);
        ^
    at assertEquals (https://deno.land/std@0.144.0/testing/asserts.ts:176:9)
    at file:///C:/Documents/test/test.ts:15:5

 FAILURES

http-request-host =&gt; ./test.ts:4:6

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out (59ms)

error: Test failed
"><pre class="notranslate"><code class="notranslate">

http-request-host ... FAILED (30ms)

 ERRORS

http-request-host =&gt; ./test.ts:4:6
error: AssertionError: Values are not equal:


    [Diff] Actual / Expected


-   http://127.0.0.1:5000/
+   http://localhost.hello.world:9900/


  throw new AssertionError(message);
        ^
    at assertEquals (https://deno.land/std@0.144.0/testing/asserts.ts:176:9)
    at file:///C:/Documents/test/test.ts:15:5

 FAILURES

http-request-host =&gt; ./test.ts:4:6

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out (59ms)

error: Test failed

</code></pre></div>
<p dir="auto">Hey, I've look for the similar problem in stackoverflow and here in the repository but I haven't found anything. I hope it's not a duplicate.</p>
<p dir="auto">I'm running subprocess command using code like this:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const process = Deno.run({ cmd, stdout: &quot;piped&quot;, stderr: &quot;piped&quot; });

const buffer = await process.output();
const str = new TextDecoder().decode(buffer);
console.log(str);

process.close();"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-s1">process</span> <span class="pl-c1">=</span> <span class="pl-smi">Deno</span><span class="pl-kos">.</span><span class="pl-en">run</span><span class="pl-kos">(</span><span class="pl-kos">{</span> cmd<span class="pl-kos">,</span> <span class="pl-c1">stdout</span>: <span class="pl-s">"piped"</span><span class="pl-kos">,</span> <span class="pl-c1">stderr</span>: <span class="pl-s">"piped"</span> <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-k">const</span> <span class="pl-s1">buffer</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-s1">process</span><span class="pl-kos">.</span><span class="pl-en">output</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">str</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-smi">TextDecoder</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">decode</span><span class="pl-kos">(</span><span class="pl-s1">buffer</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s1">str</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-s1">process</span><span class="pl-kos">.</span><span class="pl-en">close</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">The command that I'm running is "persistent"/"not exiting" and it doesn't close but just waits for the connections and then it displays some data to the output. However, Deno expects subprocess to close and then display some data. I've also tried iterating over <code class="notranslate">stdout</code> with <code class="notranslate">Deno.iter</code> but the same effect - nothing is logged to the console.</p>
<p dir="auto">How can I run "persistent"/"not exiting" subprocess and still be able to get output whenever something is written to stdout?</p>