Skip to content

Instantly share code, notes, and snippets.

@srveit
Created August 19, 2010 23:40
Show Gist options
  • Save srveit/539219 to your computer and use it in GitHub Desktop.
Save srveit/539219 to your computer and use it in GitHub Desktop.
/*globals
encode_multipart_message: false
setTimeout: false, clearTimeout: false
*/
require("./multipart_encode_verification");
var httped = require("./httped");
var events = require("events");
var sys = require("sys");
var user_agent_name = "Node-Agent/4.0.0";
var createRequest = function (httpClient, verification_details) {
var path = '/remote/service';
var method = "POST";
var timeout = 1000; // ms
var accept = "application/json";
var boundary = "4aee6c670ead113bcd89fc83b470f4d8f1d6be15";
var content_type = "multipart/form-data; boundary=" + boundary;
var body = encode_multipart_message(verification_details, boundary);
var httpRequest =
httpClient.request(method, path, accept, content_type, body, timeout);
var request = new events.EventEmitter();
httpRequest.
addListener('parsedResponse', function (parsedBody) {
request.emit("verificationComplete", parsedBody);
}).
addListener("error", function (exception) {
request.emit("verificationComplete",
{status: "http_client_error", exception: exception});
});
request.end = function () {
httpRequest.end();
};
return request;
};
var createClient = function (host, port) {
var client = new events.EventEmitter();
var httpClient = httped.createClient(port, host);
client.request = function (verification_details) {
return createRequest(httpClient, verification_details);
};
return client;
};
exports.createClient = createClient;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment