GithubHelp home page GithubHelp logo

Needle parses in streams mode about needle HOT 12 CLOSED

tomas avatar tomas commented on July 19, 2024
Needle parses in streams mode

from needle.

Comments (12)

tomas avatar tomas commented on July 19, 2024

Yes, that's the expected behaviour. Were you expecting something different?

The option is parse: false by the way!

from needle.

terinjokes avatar terinjokes commented on July 19, 2024

Sorry, I typo'd the issue here. 😀

The service I'm interacting with returns files, which occassionally can be JSON files, which should be saved to disk. Doing a simple needle.get and piping to fs.createWriteStream was successful until I encountered this case.

The only documentation around piping in this module shows a web request being written to disk via the same manner. Therefore it "feels" like a bug when this is violated by the stream being knocked into object mode by the JSON or XML parsers.

from needle.

tomas avatar tomas commented on July 19, 2024

I'm wondering, what makes a JSON file different from a JSON string? As far as I can see, to Needle it's basically a JSON object that should be parsed, given that the response's Content-Type says so.

I think this is more an edge case than an actual bug. :)

from needle.

tomas avatar tomas commented on July 19, 2024

@terinjokes I'm closing this one for the time being. Feel free to reopen if you think there's a better way of handling this.

from needle.

monolithed avatar monolithed commented on July 19, 2024
var stream = needle.request('post', url, {}, {
    decode: false,
    parse: false
});

stream.pipe(response);

stream.on('end', function () {
      // Never be fired without `parse: false`
});

@tomas, Please pay attention to this point in the documentation!

from needle.

tomas avatar tomas commented on July 19, 2024

@monolithed Is that so? What URL are you testing with?

from needle.

monolithed avatar monolithed commented on July 19, 2024

@tomas, public url like https://e.mail.ru

from needle.

tomas avatar tomas commented on July 19, 2024

@monolithed Can you share a full code example? I don't know where the response object you show comes from.

from needle.

monolithed avatar monolithed commented on July 19, 2024

@tomas,

app.use(express.cookieParser());

app.use(function (request, response, next) {
    get_cookies(function () {
          request.cookies = result.cookies;
          next();
   });
});

app.use('/api', function (request, response, next) {
    var url = 'https://e.mail.ru/api' + request.url;

    var stream = needle.request(request.method, url, request.body, {
        cookies: request.cookies,
        parse  : false
    });

    stream.pipe(response);
});

Could not close connection without parse: false. It seems very strange...

from needle.

tomas avatar tomas commented on July 19, 2024

Ok, gonna test it now. Which needle version are you running?

from needle.

tomas avatar tomas commented on July 19, 2024

I just tested and running the latest Needle (from git, not npm) I do get the 'end' event emitted. This might have to do with a few recent changes related to the Connection header.

I haven't pushed a new version to NPM because I need to update the documentation first. However you can safely run the latest version of git since all new major changes have been thoroughly covered with tests.

from needle.

monolithed avatar monolithed commented on July 19, 2024

0.11.0, thanks

from needle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.