UNPKG

nos-node.js-sdk

Version:

NOS Node.js SDK实现了NOS对象操作接口,基于此SDK能方便快速地实现JavaScript应用程序来使用NOS的对象存储服务。

84 lines (67 loc) 2.06 kB
/** * Created by hzlichaolin on 2016/7/12. */ var http = require('http'); var util = require('util'); function httpRequest() { this.accessId = null; this.secretKey = null; this.contentMD5 = null; this.contentType = null; this.expires = null; this.disposition = null; this.contentEncoding = null; this.cacheControl = null; this.contentLanguage = null; } httpRequest.prototype.setHost = function (host) { this.options.host = host; }; httpRequest.prototype.setPort = function (port) { this.options.port = port; }; httpRequest.prototype.setAccessId = function (accessId) { this.accessId = accessId; }; httpRequest.prototype.setSecretKey = function (secretKey) { this.secretKey = secretKey; }; httpRequest.prototype.setContentMD5 = function (contentMD5) { this.contentMD5 = contentMD5; }; httpRequest.prototype.setContentType = function (contentType) { this.contentType = contentType; }; httpRequest.prototype.setExpires = function (expires) { this.expires = expires; }; httpRequest.prototype.setDisposition = function (disposition) { this.disposition = disposition; }; httpRequest.prototype.setEncoding = function (encoding) { this.contentEncoding = encoding; }; httpRequest.prototype.setCacheControl = function (cacheControl) { this.cacheControl = cacheControl; }; httpRequest.prototype.setLanguage = function (language) { this.contentLanguage = language; }; httpRequest.prototype.sendRequest = function (options,func) { options.headers['User-Agent'] = 'nos-node.js-sdk version=0.0.1'; var req = http.request(options, func); req.on('error', function(err){ util.log('REQUEST ERROR: ' + err); }); if (options.body != null){ if (options.method == 'PUT'){ options.body.pipe(req); }else{ req.write(options.body ,'binary') req.end(); } }else { req.end(); } } module.exports = httpRequest;