These are chat archives for request/request

4th
Aug 2017
sezanzeb
@sezanzeb
Aug 04 2017 12:31
hi. the on('data') listener provides me with half messages
on clients i am using EventSources and an on('message') listener and it works there. I think i have seen the same issue with uncomplete messages on clients before
is there some listener that reacts when a complete message (terminated with \n\n) from a stream comes in?
sezanzeb
@sezanzeb
Aug 04 2017 12:51
i managed to solve it by using a variable that stores incomplete messages and when the final chunks arrive it concatinates them finally
sezanzeb
@sezanzeb
Aug 04 2017 13:06
how do you even close the stream
Felipe Sabino
@felipesabino
Aug 04 2017 13:06

i managed to solve it by using a variable that stores incomplete messages and when the final chunks arrive it concatinates them finally

That’s exactly what you shold do when dealing with streams. There is an example of that here https://github.com/request/request#examples and also the stream docs are pretty clear that ’data’ is a chunk of data https://nodejs.org/api/stream.html#stream_event_data

sezanzeb
@sezanzeb
Aug 04 2017 13:09
thanks
Felipe Sabino
@felipesabino
Aug 04 2017 13:13

@sezanzeb

how do you even close the stream

Hmmm I never had to do that, but I would try listening to ’message’ event to get the http.IncomingMessage object - https://nodejs.org/api/http.html#http_class_http_incomingmessage -, which is itself a Readable Stream, ant then I would try calling destroy https://nodejs.org/api/http.html#http_message_destroy_error
I would also be careful on how the ’error’ events are handled, as destroy would emit those.

Let me know if that works :wink:

sezanzeb
@sezanzeb
Aug 04 2017 13:20
i'm having a stream between two node.js servers, like that: let request = request.get("http://www.localhost:4000" + path).on("data"...
calling request.end() or request.destroy() does not stop the server on 4000 from sending messages
a "message" event like this: on("message",(message) => foo()) is never triggered
Felipe Sabino
@felipesabino
Aug 04 2017 13:27

calling request.end() or request.destroy() does not stop the server on 4000 from sending messages
a "message" event like this: on("message",(message) => foo()) is never triggered

AFAIK and based on your code sample you should call message.destroy() not request.destroy
Also, I guess you are registering for the wrong event, it is not on(“message”, …), it is on(“response”,…)

on(“response”, (message) => message.destroy())
sezanzeb
@sezanzeb
Aug 04 2017 13:45
ah amazing. I had to store the message object from response in a variable and then i was able to stop it at a later point. works now
thanks a lot. really
Felipe Sabino
@felipesabino
Aug 04 2017 14:09

thanks a lot. really

glad to know it worked :tada: