Old source do not add content-length header automatically
with form-data. If body is instance of form-data, Users
must missing this header. It cause parse error with some
server engine like WSGI. WSGI must drop body if this was not
set, and WSGI based frameworks such as flask can not read
form data.
For example, this python code with flask..
----
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/', method=['POST'])
def index():
return jsonify(**request.form)
app.run()
----
Can not receive any data from this code.
----
require('es6-promise').polyfill();
var fetch = require('isomorphic-fetch'); // it use node-fetch
var FormData = require('form-data');
var data = new FormData();
data.append('name', 'item4');
data.append('message', 'it is test!');
fetch('http://localhost:5000', {method: 'POST', body: data})
.then(function (data) {
return data.json();
})
.then(function (data) {
console.log(data);
});
----
This commit just use FormData's getLengthSync method.