Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading incoming HTTP headers with node.js

Now as example, I'm getting an response which has partially the key/values as an javascript object:

status: '200 OK',
'content-encoding': 'gzip'

I can easily read out and log the status message by: headers.status but when I try to log the content-encoding (which I need in this particular situation) it errors on:

headers.'content-encoding' <- obviously the quotes it doesn't like
headers.content-encoding <- obviously the '-' it doesn't like

How am I suppose to get/read/log it's content-encoding value?

Greets,

m0rph3v5

like image 667
M0rph3v5 Avatar asked Dec 28 '10 13:12

M0rph3v5


1 Answers

Javascript also supports square bracket notation for referring to properties so if headers is an appropriate object, you can use headers['content-encoding'].

like image 182
Sanjay T. Sharma Avatar answered Oct 05 '22 17:10

Sanjay T. Sharma