kitejs
Version:
the rpc framework Kite for Node.js
36 lines (29 loc) • 935 B
text/typescript
/**
* @author xiangshouding
* @file protocol/http.ts
*/
import {Map} from '../types/lang';
import {Address, Protocol} from './protocol';
import * as request from 'request';
type Method = 'GET' | 'POST' | 'DELETE' | 'OPTION';
export class Http implements Protocol {
method: Method = 'GET';
addr: Address;
options: Map<string>;
timeout: number = 2000; // 2s
path: string;
constructor(addr: Address, options?: Map<any>) {
this.options = options || {
method: 'GET'
};
if (!this.options['url'] && !this.options['uri']) {
let path = this.options['path'] || '';
path = (path.indexOf('/') === 0 ? '' : '/') + path;
this.options['url'] = `http://${addr.getAddress()}${path}`;
}
}
createConnection() {}
request(cb: (err: any, service: any, conn: any) => void) {
return request(this.options, cb);
}
}