Skip to content

return request from .submit() #47

Closed

Description

@tj

does a limbo return for some reason: https://github.com/felixge/node-form-data/blob/master/lib/form_data.js#L295

need this to track progress etc

Activity

  1. felixge commented on Aug 20, 2013

    @felixge
    Contributor

    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?

  2. alexindigo commented on Aug 20, 2013

    @alexindigo
    Member

    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?

  3. tj commented on Aug 20, 2013

    @tj
    Author

    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

  4. tj commented on Aug 20, 2013

    @tj
    Author

    @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

  5. alexindigo commented on Aug 20, 2013

    @alexindigo
    Member

    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.

  6. alexindigo commented on Aug 20, 2013

    @alexindigo
    Member

    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?

  7. tj commented on Aug 21, 2013

    @tj
    Author

    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

  8. added a commit that references this issue on Aug 21, 2013
  9. alexindigo commented on Aug 21, 2013

    @alexindigo
    Member

    @visionmedia @felixge Something like that.

  10. added 2 commits that reference this issue on Aug 22, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions