These are chat archives for request/request

23rd
Dec 2014
Uzo Olisemeka
@Akamaozu
Dec 23 2014 13:11

hi :)

is it possible to grab just the headers, or is there an event that fires as soon as request gets the headers of the url?

i want to grab the content length and if possible make a progress meter on the state of request's transfer
Nicolai Kamenzky
@analog-nico
Dec 23 2014 14:44
Hi @Akamaozu Did you try request.head(...)? This could be exactly what you need.
Uzo Olisemeka
@Akamaozu
Dec 23 2014 15:41
Wow I never knew that method existed!
Thank you so much, @analog-nico!
i literally had to search the readme to find it because I'd never seen it before. Thank you so much! :)
Uzo Olisemeka
@Akamaozu
Dec 23 2014 15:48
i wonder if there is something like request(...).on('header', callback) so I can fire off an event when the header is received without initiating a second request.
A convenience method, really. Although I have no problem with what's been given already. I can definitely work with just this. Thanks again, @analog-nico! I really appreciate the help :)
Nicolai Kamenzky
@analog-nico
Dec 23 2014 16:28
You are welcome @Akamaozu
There is no 'header' event or similar. Maybe the first 'data' event will help you. However, I couldn't tell since I didn't use this before.
Nicolai Kamenzky
@analog-nico
Dec 23 2014 16:38
Oh no, @Akamaozu I might have told you wrong: Check out the 'response' event. From reading the source code it might actually be exactly what you meant by your header event.
Uzo Olisemeka
@Akamaozu
Dec 23 2014 16:39
@analog-nico currently playing with it, but i can't find any documentation on it. i should have jumped straight into the source to get more info about it.
Nicolai Kamenzky
@analog-nico
Dec 23 2014 16:39

Nailed it. ;) It in the docs:

Request emits a "response" event when a response is received. The response argument will be an instance of http.IncomingMessage.

request
  .get('http://google.com/img.png')
  .on('response', function(response) {
    console.log(response.statusCode) // 200
    console.log(response.headers['content-type']) // 'image/png'
  })
  .pipe(request.put('http://mysite.com/img.png'))
Uzo Olisemeka
@Akamaozu
Dec 23 2014 16:40
@analog-nico my hero!
Nicolai Kamenzky
@analog-nico
Dec 23 2014 16:40
:D
Uzo Olisemeka
@Akamaozu
Dec 23 2014 16:41
@analog-nico if you're ever in Nigeria, I owe you a beer.
@analog-nico and the cure for ebola, just in case
Nicolai Kamenzky
@analog-nico
Dec 23 2014 16:41
I would like to check out Nigerian beers. +1 :)
Uzo Olisemeka
@Akamaozu
Dec 23 2014 16:43
Note to self ... ebola is no laughing matter on the internet
Seriously though, thank you so much, @analog-nico. Your doc grepping skills are superb. I have a long way to go
Nicolai Kamenzky
@analog-nico
Dec 23 2014 16:46
You are welcome @Akamaozu
Happy coding!
Leonardo Lazzaro
@llazzaro
Dec 23 2014 21:18
Hi. Question about request using post. I know how to post a form, but how I could post a json body? I want to do a post with data
simo
@simov
Dec 23 2014 21:18
json:{some:'data'}
Leonardo Lazzaro
@llazzaro
Dec 23 2014 21:29
awesome, thanks!