Merge pull request +13142 from c9/all-fix-rest-client-content-length

All fix rest client content length
pull/282/head
Fabian Jakobs 2016-03-31 12:58:50 +02:00
commit 611bf393cd
2 zmienionych plików z 56 dodań i 1 usunięć

2
node_modules/c9/rest_client.js wygenerowano vendored
Wyświetl plik

@ -36,7 +36,7 @@ function RestClient(host, port, config) {
var headers = _.extend({
"Accept": "application/json",
"Content-Type": "application/json",
"Content-Length": payload.length
"Content-Length": Buffer.byteLength(payload)
}, config.headers || {});
var options = {

55
node_modules/c9/rest_client_test.js wygenerowano vendored 100644
Wyświetl plik

@ -0,0 +1,55 @@
#!/usr/bin/env node
/*global describe it before after beforeEach afterEach */
"use strict";
"use server";
"use mocha";
require("c9/inline-mocha")(module);
require("amd-loader");
var assert = require("assert");
var http = require("http");
var findFreePort = require("netutil").findFreePort;
var RestClient = require("./rest_client");
describe(__filename, function() {
var port;
var MIN_API_PORT = 18500;
var MAX_API_PORT = MIN_API_PORT + 1000;
beforeEach(function(next) {
findFreePort(MIN_API_PORT, MAX_API_PORT, 'localhost', function(err, _port) {
port = _port;
next(err);
});
});
it("should send correct content length", function(next) {
var server = http.createServer(function(req, res) {
var body = "";
req.on("data", function(d) {
body += d;
});
req.on("end", function() {
JSON.parse(body);
res.end("OK");
});
});
server.listen(port, function() {
var client = new RestClient("localhost", port, {});
// send body with "strange" unicode character
var body = {"cloneFromScm":"https://github.com/saasbook/ruby­-calisthenics"};
client.request("POST", "/", body, function(err, res) {
assert(!err, err);
assert.equal(res, "OK");
server.close(next);
});
});
});
});