1+ const  urllib  =  require ( 'urllib' ) ; 
2+ 
13const  pkg  =  require ( '../package.json' ) ; 
24const  conf  =  require ( './conf' ) ; 
35const  digest  =  require ( './auth/digest' ) ; 
@@ -131,9 +133,16 @@ function postWithoutForm (requestURI, token, callbackFunc) {
131133} 
132134
133135function  get  ( requestUrl ,  headers ,  callbackFunc )  { 
136+     headers  =  headers  ||  { } ; 
137+     headers [ 'User-Agent' ]  =  headers [ 'User-Agent' ]  ||  conf . USER_AGENT ; 
138+     headers . Connection  =  'keep-alive' ; 
139+ 
134140    const  data  =  { 
141+         method : 'GET' , 
142+         headers : headers , 
135143        dataType : 'json' , 
136-         timeout : conf . RPC_TIMEOUT 
144+         timeout : conf . RPC_TIMEOUT , 
145+         gzip : true 
137146    } ; 
138147
139148    if  ( conf . RPC_HTTP_AGENT )  { 
@@ -144,16 +153,22 @@ function get (requestUrl, headers, callbackFunc) {
144153        data . httpsAgent  =  conf . RPC_HTTPS_AGENT ; 
145154    } 
146155
147-     return  exports . qnHttpClient . get ( { 
148-         url :  requestUrl , 
149-         headers :  headers , 
150-         callback :  callbackFunc 
151-     } ,   data ) ; 
156+     return  urllib . request ( 
157+         requestUrl , 
158+         data , 
159+         callbackFunc 
160+     ) ; 
152161} 
153162
154- function  post  ( requestURL ,  requestForm ,  headers ,  callbackFunc )  { 
163+ function  post  ( requestUrl ,  requestForm ,  headers ,  callbackFunc )  { 
155164    // var start = parseInt(Date.now() / 1000); 
165+     headers  =  headers  ||  { } ; 
166+     headers [ 'User-Agent' ]  =  headers [ 'User-Agent' ]  ||  conf . USER_AGENT ; 
167+     headers . Connection  =  'keep-alive' ; 
168+ 
156169    const  data  =  { 
170+         headers : headers , 
171+         method : 'POST' , 
157172        dataType : 'json' , 
158173        timeout : conf . RPC_TIMEOUT , 
159174        gzip : true 
@@ -168,17 +183,30 @@ function post (requestURL, requestForm, headers, callbackFunc) {
168183        data . httpsAgent  =  conf . RPC_HTTPS_AGENT ; 
169184    } 
170185
171-     return  exports . qnHttpClient . post ( { 
172-         url : requestURL , 
173-         data : requestForm , 
174-         headers : headers , 
175-         callback : callbackFunc 
176-     } ,  data ) ; 
186+     if  ( Buffer . isBuffer ( requestForm )  ||  typeof  requestForm  ===  'string' )  { 
187+         data . content  =  requestForm ; 
188+     }  else  if  ( requestForm )  { 
189+         data . stream  =  requestForm ; 
190+     }  else  { 
191+         data . headers [ 'Content-Length' ]  =  0 ; 
192+     } 
193+ 
194+     return  urllib . request ( 
195+         requestUrl , 
196+         data , 
197+         callbackFunc 
198+     ) ; 
177199} 
178200
179- function  put  ( requestURL ,  requestForm ,  headers ,  callbackFunc )  { 
201+ function  put  ( requestUrl ,  requestForm ,  headers ,  callbackFunc )  { 
180202    // var start = parseInt(Date.now() / 1000); 
203+     headers  =  headers  ||  { } ; 
204+     headers [ 'User-Agent' ]  =  headers [ 'User-Agent' ]  ||  conf . USER_AGENT ; 
205+     headers . Connection  =  'keep-alive' ; 
206+ 
181207    const  data  =  { 
208+         headers : headers , 
209+         method : 'PUT' , 
182210        dataType : 'json' , 
183211        timeout : conf . RPC_TIMEOUT , 
184212        gzip : true 
@@ -193,10 +221,17 @@ function put (requestURL, requestForm, headers, callbackFunc) {
193221        data . httpsAgent  =  conf . RPC_HTTPS_AGENT ; 
194222    } 
195223
196-     return  exports . qnHttpClient . put ( { 
197-         url : requestURL , 
198-         data : requestForm , 
199-         headers : headers , 
200-         callback : callbackFunc 
201-     } ,  data ) ; 
224+     if  ( Buffer . isBuffer ( requestForm )  ||  typeof  requestForm  ===  'string' )  { 
225+         data . content  =  requestForm ; 
226+     }  else  if  ( requestForm )  { 
227+         data . stream  =  requestForm ; 
228+     }  else  { 
229+         data . headers [ 'Content-Length' ]  =  0 ; 
230+     } 
231+ 
232+     return  urllib . request ( 
233+         requestUrl , 
234+         data , 
235+         callbackFunc 
236+     ) ; 
202237} 
0 commit comments