Giter VIP home page Giter VIP logo

Comments (8)

felixge avatar felixge commented on May 24, 2024

Hm, seems like the request object needs the Content-Length in order be constructed. Since getting the value for that is async it can't be returned right away. Got an idea for a patch?

from form-data.

alexindigo avatar alexindigo commented on May 24, 2024

We can create request object before async call and return it and populate it later. But I was thinking that it's might be confusing to return httpRequest from FormData, since people might expect it to be same object.
Maybe we'll be better off just translating events.

@visionmedia How are you going track the progress on httpRequest?

from form-data.

tj avatar tj commented on May 24, 2024

unfortunate we can't initialize a node request to return (that I know of at least), emitting an event would be pretty weird, two callbacks is weird. I just wrote submit() with the progress stuff built in but im not sure what would be best in here. hmm yeah aside from an event or second callback I'm not sure

from form-data.

tj avatar tj commented on May 24, 2024

@alexindigo I'm just proxying the .write() to the request with this hack:

    var write = req.write;
    req.write = function(chunk){
      return write.call(this, chunk, function(){
        form.emit('progress', chunk, len);
      });
    };

and later using that to do the actual progress reporting. Maybe if we make that stuff into a little module and just do trackProgress(req).on('progress', re-emit crap here) we could add it to form-data :s haha, but no point turning it into another request library

from form-data.

alexindigo avatar alexindigo commented on May 24, 2024

How about?

if (params.request) {
  request = params.request;
} else {
  // https if specified, fallback to http in any other case
  if (params.protocol == 'https:') {
    // override default port
    if (!params.port) options.port = 443;
    request = https.request;
  } else {
    request = http.request;
  }
}

request = request(options);

then you can have your own augmented request instantiation function.

from form-data.

alexindigo avatar alexindigo commented on May 24, 2024

Oh, looks like we still can add content-length later:

"The header is still mutable using the setHeader(name, value), getHeader(name), removeHeader(name) API. The actual header will be sent along with the first data chunk or when closing the connection."

But, again, don't you think it will be confusing to return httpRequest from FormData.submit?

from form-data.

tj avatar tj commented on May 24, 2024

I think returning it is the most sensible thing personally, especially since it wont break anyone's apps since it's not returning this for chaining

from form-data.

alexindigo avatar alexindigo commented on May 24, 2024

@visionmedia @felixge Something like that.

from form-data.

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.