deno_std: console.log(headers) doesn't print useful info

I have problems to read the headers of a ServerRequest. I have updated the dependencies with the --reload flag, but the error still exists. Is this a Bug or am i doing it wrong?

This is the Code i use:

import { serve } from "https://deno.land/std/http/server.ts";

const test = async () => {
  const _s = serve('0.0.0.0:8000')

  for await (const req of _s) {
    console.log(req.headers)
    req.respond({ body: new TextEncoder().encode("Hello World\n") })
  }
}

test();

let res = fetch('http://0.0.0.0:8000/test', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json; charset=UTF-8',
    'test': 'test'
  },
  body: 'test'
}).then(res => res)

res = fetch('http://0.0.0.0:8000/test').then(res => res)

This is the console output i get:

Headers {}
Headers {}

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (9 by maintainers)

Most upvoted comments

By submitting a PR adding it to the Headers class. I think we need to remove most of the case logic in the inspect() to this symbol anyways, as it would be tightly coupled to the class it represents than located specifically in the logic of inspect().

In the case of internal Deno code, you would need to import { customInspect } from "./console";, but the concept is the same.

Here’s a possible implementation:

function renderHeaders(headers: Headers) {
    console.log('Headers {')
    for (const [header, value] of headers.entries()) {
      console.log(`  ${header}: ${value}`)
    }
    console.log('}')
  }

Should I open a PR in Deno core?

My bad, i was just to stupid:

for (let header of req.headers.entries()) console.log(header)

does the trick