Quark
#
Modules #
quark/actionquark/appquark/bubblesquark/bufferquark/checkboxquark/cssquark/ctrquark/dialogquark/eventquark/fontquark/fsquark/hashquark/httpquark/indexquark/jsonbquark/keyboardquark/mediaquark/navquark/netquark/osquark/pathquark/pkgquark/screenquark/stepperquark/storagequark/testquark/typesquark/utilquark/viewquark/windowquark/wsquark/_bufferquark/_commonquark/_eventquark/_extquark/_md5quark/_sha1quark/_sha256quark/_utilquark/_watching
Quark v1.3.0 Documentation
Table of Contents
-
quark/http
- Enum: HttpMethod
- Enum: HttpReadyState
- StreamResponseCallback
- HttpEvent
-
Class: NativeHttpClientRequest
- NativeHttpClientRequest
- nativehttpclientrequest.uploadTotal
- nativehttpclientrequest.uploadSize
- nativehttpclientrequest.downloadTotal
- nativehttpclientrequest.downloadSize
- nativehttpclientrequest.readyState
- nativehttpclientrequest.statusCode
- nativehttpclientrequest.url
- nativehttpclientrequest.httpResponseVersion
- nativehttpclientrequest.setMethod(method)
- nativehttpclientrequest.setUrl(url)
- nativehttpclientrequest.setSavePath(path)
- nativehttpclientrequest.setUsername(user)
- nativehttpclientrequest.setPassword(pwd)
- nativehttpclientrequest.disableCache(disable)
- nativehttpclientrequest.disableCookie(disable)
- nativehttpclientrequest.disableSendCookie(disable)
- nativehttpclientrequest.disableSslVerify(disable)
- nativehttpclientrequest.setKeepAlive(keepAlive)
- nativehttpclientrequest.setTimeout(timeoutMs)
- nativehttpclientrequest.setRequestHeader(name,value)
- nativehttpclientrequest.setForm(formName,value)
- nativehttpclientrequest.setUploadFile(formName,localPath)
- nativehttpclientrequest.clearRequestHeader()
- nativehttpclientrequest.clearFormData()
- nativehttpclientrequest.getResponseHeader(headerName)
- nativehttpclientrequest.getAllResponseHeaders()
- nativehttpclientrequest.send(data?)
- nativehttpclientrequest.pause()
- nativehttpclientrequest.resume()
- nativehttpclientrequest.abort()
- Class: HttpClientRequest
- Interface: RequestOptions
- Interface: ResponseData
- request(options)
- requestStream(options,cb)
- requestSync(options)
- download(url,save)
- upload(url,localFilePath)
- get(url)
- getStream(url,cb)
- post(url,data)
- getSync(url)
- postSync(url,data)
- downloadSync(url,save)
- uploadSync(url,localPath)
- abort(id)
- userAgent()
- setUserAgent(ua)
- cachePath()
- setCachePath(path)
- maxConnectPoolSize()
- setMaxConnectPoolSize(size)
- clearCache()
- clearCookie()
quark/http #
Enum: HttpMethod #
HttpMethod #
GET
GET wayPOST
POST wayHEAD
HEAD wayDELETE
DELETE wayPUT
PUT way
Enum: HttpReadyState #
HttpReadyState #
Initial
InitialReady
ReadySending
SendingResponse
ResponseCompleted
Completed
StreamResponseCallback #
@callbackStreamResponseCallback(stream)@paramstream:StreamResponse
HttpEvent #
@typeHttpEvent=Event<HttpClientRequest,T>@template<T>
Class: NativeHttpClientRequest #
NativeHttpClientRequest #
@extendsNotification@private
nativehttpclientrequest.uploadTotal #
Total amount of data to be uploaded to the server
@getuploadTotal:number
nativehttpclientrequest.uploadSize #
The data size has been written and uploaded to the server
@getuploadSize:number
nativehttpclientrequest.downloadTotal #
Total amount of data to be downloaded
@getdownloadTotal:number
nativehttpclientrequest.downloadSize #
Downloaded data volume
@getdownloadSize:number
nativehttpclientrequest.readyState #
Request ready state
@getreadyState:HttpReadyState
nativehttpclientrequest.statusCode #
Response status code
@getstatusCode:number
nativehttpclientrequest.url #
Request target url
@geturl:string
nativehttpclientrequest.httpResponseVersion #
Response http version
@gethttpResponseVersion:string
nativehttpclientrequest.setMethod(method) #
Setting method way at request
@parammethod:HttpMethod@returnvoid
nativehttpclientrequest.setUrl(url) #
Setting request url
nativehttpclientrequest.setSavePath(path) #
Setting local save path for downloading
nativehttpclientrequest.setUsername(user) #
Setting login username
nativehttpclientrequest.setPassword(pwd) #
Setting login password
nativehttpclientrequest.disableCache(disable) #
Disable or enable the cache
nativehttpclientrequest.disableCookie(disable) #
Disable or enable the cookie
nativehttpclientrequest.disableSendCookie(disable) #
Disable or enable the sending of cookie
nativehttpclientrequest.disableSslVerify(disable) #
Disable or enable the SSL verify
nativehttpclientrequest.setKeepAlive(keepAlive) #
Setting whether to keep active
nativehttpclientrequest.setTimeout(timeoutMs) #
Setting request timeout time
nativehttpclientrequest.setRequestHeader(name,value) #
Setting request header k/v
nativehttpclientrequest.setForm(formName,value) #
Setting the request form
nativehttpclientrequest.setUploadFile(formName,localPath) #
Setting the upload file path
nativehttpclientrequest.clearRequestHeader() #
Clear request all of headers
@returnvoid
nativehttpclientrequest.clearFormData() #
Clear request all of form data
@returnvoid
nativehttpclientrequest.getResponseHeader(headerName) #
Getting response header by the name
nativehttpclientrequest.getAllResponseHeaders() #
Getting all of response headers
@returnDict<string>
nativehttpclientrequest.send(data?) #
Start send the request
@paramdata?:string|Uint8Array@returnvoid
nativehttpclientrequest.pause() #
Pause accepat the response data
@returnvoid
nativehttpclientrequest.resume() #
Resume accepat the response data
@returnvoid
nativehttpclientrequest.abort() #
Abort current request and response
@returnvoid
Class: HttpClientRequest #
HttpClientRequest #
@extendsNativeHttpClientRequest
For example:
import path from 'quark/path'
import * as fs from 'quark/fs'
var cl = new HttpClientRequest()
cl.setUrl('https://www.baidu.com/')
cl.setSavePath(path.documents('baidu.html'));
cl.onError.on(function(ev) { console.log(ev.data) })
// Prints:
// <Buffer 3c 68 74 6d 6c 3e 0d ... >
// <Buffer 3c 21 44 4f 43 54 59 ... >
// ...
cl.onData.on(function(ev) {
console.log(ev.data);
})
cl.onEnd.on(function() {
// Prints:
// true
// 4 200
console.log(fs.existsSync(path.documents('baidu.html')))
console.log(cl.readyState, cl.statusCode)
})
cl.onReadystateChange.on(function() { console.log(cl.readyState, cl.statusCode) })
cl.send();
var cl2 = new HttpClientRequest()
cl2.setUrl('http://192.168.1.100:1026/Tools/uploadFile')
cl2.setMethod(HttpMethod.POST);
cl2.setUploadFile('uploadFile', path.resources('util/http.js'))
cl2.onEnd.on(function() {
// Prints: complete
console.log('complete')
})
cl2.send();
httpclientrequest.onError #
Trigger when an error occurs
@eventonError:EventNoticer<HttpEvent<Error>>
httpclientrequest.onWrite #
Trigger when write data to the server
@eventonWrite:EventNoticer<HttpEvent>
httpclientrequest.onHeader #
Trigger when accept headers complete
@eventonHeader:EventNoticer<HttpEvent>
httpclientrequest.onData #
Trigger when accept part of body data, and will be continuous
@eventonData:EventNoticer<HttpEvent<Uint8Array>>
httpclientrequest.onEnd #
Trigger when ended a request and response
@eventonEnd:EventNoticer<HttpEvent>
httpclientrequest.onReadystateChange #
Trigger when changed readystate
@eventonReadystateChange:EventNoticer<HttpEvent>
httpclientrequest.onTimeout #
Trigger when a request timeout
@eventonTimeout:EventNoticer<HttpEvent>
httpclientrequest.onAbort #
Trigger when a request is actively abort
@eventonAbort:EventNoticer<HttpEvent>
Interface: RequestOptions #
RequestOptions #
requestoptions.url? #
The target path url to request
url?:string
requestoptions.method? #
The method way to request
method?:HttpMethod
requestoptions.headers? #
setting custom request headers
headers?:Dict<string>
requestoptions.postData? #
Non post requests ignore this option
postData?:string|Uint8Array
requestoptions.save? #
save body content to local disk
save?:string
requestoptions.upload? #
upload loacl file
upload?:string
requestoptions.timeout? #
request timeout time, default no timeout "0"
timeout?:number
requestoptions.disableSslVerify? #
Is disable ssl verify
disableSslVerify?:boolean
requestoptions.disableCache? #
Is disable cache
disableCache?:boolean
requestoptions.disableCookie? #
Is disable cookie
disableCookie?:boolean
Interface: ResponseData #
ResponseData #
responsedata.data #
response data
data:Uint8Array
responsedata.httpVersion #
http version
httpVersion:string
responsedata.statusCode #
status code
statusCode:number
responsedata.responseHeaders #
response headers
responseHeaders:Dict<string>
request(options) #
Sending HTTP request by the options
For example:
import path from 'quark/path'
// uploat file and save body data
var opts = {
url: 'http://192.168.1.100:1026/Tools/uploadFile',
method: HttpMethod.POST,
headers: { test: 'test' },
// postData: 'a=A',
save: path.documents('uploadFile.html'),
upload: path.resources('util/http.js'),
disableSslVerify: false,
disableCache: true,
disableCookie: false,
};
request(opts).then(function(buff) {
// Prints: <Buffer ...>
console.log(buff)
}).catch(e=>{
// Fail
})
@paramoptions:RequestOptions@returnAsyncTask<ResponseData>
requestStream(options,cb) #
Sending HTTP request with stream way by the options
For example:
requestStream({
url: 'http://192.168.1.100:1026/'
}, (d)=>{
// Prints: <Buffer ...>
console.log(d.data)
}).then(function() {
console.log('Ok')
}).catch(err=>{
//Fail
});
@paramoptions:RequestOptions@paramcb:StreamResponseCallback@returnAsyncTask<void>
requestSync(options) #
Sending HTTP sync request by the options
For example:
// Prints: <Buffer ...>
try {
console.log(http.requestSync({ url: 'http://192.168.1.100:1026/' }));
} catch(e) {
//Fail
}
@paramoptions:RequestOptions@returnUint8Array
download(url,save) #
Sending HTTP request with get way and save response data
@paramurl:stringrequest target url@paramsave:stringlocal save path@returnAsyncTask<ResponseData>
upload(url,localFilePath) #
Uploading local file data with post way
@paramurl:stringrequest target url@paramlocalFilePath:stringlocal file path@returnAsyncTask<ResponseData>
get(url) #
Requesting HTTP data in GET way
@paramurl:string@returnAsyncTask<ResponseData>
getStream(url,cb) #
Requesting HTTP data in GET way and and using the stream way receiving data
@paramurl:string@paramcb:StreamResponseCallback@returnAsyncTask<void>
post(url,data) #
Sending data to server in POST way
@paramurl:string@paramdata:string|Uint8Array@returnAsyncTask<ResponseData>
getSync(url) #
Syncing request HTTP data in GET way
@paramurl:string@returnUint8Array
postSync(url,data) #
Syncing send data to server by POST
@paramurl:string@paramdata:string|Uint8Array@returnUint8Array
downloadSync(url,save) #
Syncing download data from the url path and save to local path
@paramurl:string@paramsave:string@returnUint8Array
uploadSync(url,localPath) #
Syncing upload data to server in the POST way
@paramurl:stringtarget server url@paramlocalPath:stringlocal file path@returnUint8Array
abort(id) #
abort async task by id
userAgent() #
Getting default http user-agent header
@returnstring
setUserAgent(ua) #
Setting default http user-agent header
cachePath() #
Getting HTTP cache saving path
@returnstring
setCachePath(path) #
Setting local HTTP cache saving path
maxConnectPoolSize() #
Getting network connection pool size
@returnUint
setMaxConnectPoolSize(size) #
Setting network connection pool size
clearCache() #
To clear all of caches
@returnvoid
clearCookie() #
To clear all of cookies
@returnvoid