Created
August 19, 2010 23:40
-
-
Save srveit/539219 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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