Quark
#
Modules #
quark/actionquark/appquark/bubblesquark/bufferquark/checkboxquark/cssquark/ctrquark/defsquark/dialogquark/eventquark/fontquark/fsquark/hashquark/httpquark/indexquark/jsonbquark/keyboardquark/lmdbquark/mediaquark/navquark/netquark/osquark/pathquark/pkgquark/screenquark/statequark/stepperquark/storagequark/testquark/typesquark/uriquark/utilquark/viewquark/windowquark/wsquark/_bufferquark/_commonquark/_decoratorsquark/_eventquark/_extquark/_md5quark/_sha1quark/_sha256quark/_utilquark/_watching
Quark v1.4.0 Documentation
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 #
type HttpEvent<T = void> = Event<HttpClientRequest,T>
Class: NativeHttpClientRequest #
NativeHttpClientRequest #
Extends: Notification
nativehttpclientrequest.uploadTotal #
Total amount of data to be uploaded to the server
readonly uploadTotal: number
nativehttpclientrequest.uploadSize #
The data size has been written and uploaded to the server
readonly uploadSize: number
nativehttpclientrequest.downloadTotal #
Total amount of data to be downloaded
readonly downloadTotal: number
nativehttpclientrequest.downloadSize #
Downloaded data volume
readonly downloadSize: number
nativehttpclientrequest.readyState #
Request ready state
readonly readyState: HttpReadyState
nativehttpclientrequest.statusCode #
Response status code
readonly statusCode: number
nativehttpclientrequest.url #
Request target url
readonly url: string
nativehttpclientrequest.httpResponseVersion #
Response http version
readonly httpResponseVersion: string
nativehttpclientrequest.setMethod(method) #
Setting method way at request
setMethod(method: HttpMethod): void
nativehttpclientrequest.setUrl(url) #
Setting request url
setUrl(url: string): void
nativehttpclientrequest.setSavePath(path) #
Setting local save path for downloading
setSavePath(path: string): void
nativehttpclientrequest.setUsername(user) #
Setting login username
setUsername(user: string): void
nativehttpclientrequest.setPassword(pwd) #
Setting login password
setPassword(pwd: string): void
nativehttpclientrequest.disableCache(disable) #
Disable or enable the cache
disableCache(disable: boolean): void
nativehttpclientrequest.disableCookie(disable) #
Disable or enable the cookie
disableCookie(disable: boolean): void
nativehttpclientrequest.disableSendCookie(disable) #
Disable or enable the sending of cookie
disableSendCookie(disable: boolean): void
nativehttpclientrequest.disableSslVerify(disable) #
Disable or enable the SSL verify
disableSslVerify(disable: boolean): void
nativehttpclientrequest.setKeepAlive(keepAlive) #
Setting whether to keep active
setKeepAlive(keepAlive: boolean): void
nativehttpclientrequest.setTimeout(timeoutMs) #
Setting request timeout time
setTimeout(timeoutMs: Uint): void
nativehttpclientrequest.setRequestHeader(name,value) #
Setting request header k/v
setRequestHeader(name: string, value: string): void
nativehttpclientrequest.setForm(formName,value) #
Setting the request form
setForm(formName: string, value: string): void
nativehttpclientrequest.setUploadFile(formName,localPath) #
Setting the upload file path
setUploadFile(formName: string, localPath: string): void
nativehttpclientrequest.clearRequestHeader() #
Clear request all of headers
clearRequestHeader(): void
nativehttpclientrequest.clearFormData() #
Clear request all of form data
clearFormData(): void
nativehttpclientrequest.getResponseHeader(headerName) #
Getting response header by the name
getResponseHeader(headerName: string): string
nativehttpclientrequest.getAllResponseHeaders() #
Getting all of response headers
getAllResponseHeaders(): Dict<string>
nativehttpclientrequest.send(data?) #
Start send the request
send(data?: string | Uint8Array): void
nativehttpclientrequest.pause() #
Pause accepat the response data
pause(): void
nativehttpclientrequest.resume() #
Resume accepat the response data
resume(): void
nativehttpclientrequest.abort() #
Abort current request and response
abort(): void
Class: HttpClientRequest #
HttpClientRequest #
Extends: NativeHttpClientRequest
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 ms, 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
request(options: RequestOptions): AsyncTask<ResponseData>
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
})
requestStream(options,cb) #
Sending HTTP request with stream way by the options
requestStream(options: RequestOptions, cb: StreamResponseCallback): AsyncTask<void>
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
});
requestSync(options) #
Sending HTTP sync request by the options
requestSync(options: RequestOptions): Uint8Array
For example:
// Prints: <Buffer ...>
try {
console.log(http.requestSync({ url: 'http://192.168.1.100:1026/' }));
} catch(e) {
//Fail
}
download(url,save) #
Sending HTTP request with get way and save response data
download(url: string, save: string): AsyncTask<ResponseData>
Parameters:
url— request target urlsave— local save path
upload(url,localFilePath) #
Uploading local file data with post way
upload(url: string, localFilePath: string): AsyncTask<ResponseData>
Parameters:
url— request target urllocalFilePath— local file path
get(url) #
Requesting HTTP data in GET way
get(url: string): AsyncTask<ResponseData>
getStream(url,cb) #
Requesting HTTP data in GET way and and using the stream way receiving data
getStream(url: string, cb: StreamResponseCallback): AsyncTask<void>
post(url,data) #
Sending data to server in POST way
post(url: string, data: string | Uint8Array): AsyncTask<ResponseData>
getSync(url) #
Syncing request HTTP data in GET way
getSync(url: string): Uint8Array
postSync(url,data) #
Syncing send data to server by POST
postSync(url: string, data: string | Uint8Array): Uint8Array
downloadSync(url,save) #
Syncing download data from the url path and save to local path
downloadSync(url: string, save: string): Uint8Array
uploadSync(url,localPath) #
Syncing upload data to server in the POST way
uploadSync(url: string, localPath: string): Uint8Array
Parameters:
url— target server urllocalPath— local file path
abort(id) #
abort async task by id
abort(id: Int): void
userAgent() #
Getting default http user-agent header
userAgent(): string
setUserAgent(ua) #
Setting default http user-agent header
setUserAgent(ua: string): void
cachePath() #
Getting HTTP cache saving path
cachePath(): string
setCachePath(path) #
Setting local HTTP cache saving path
setCachePath(path: string): void
maxConnectPoolSize() #
Getting network connection pool size
maxConnectPoolSize(): Uint
setMaxConnectPoolSize(size) #
Setting network connection pool size
setMaxConnectPoolSize(size: Uint): void
clearCache() #
To clear all of caches
clearCache(): void
clearCookie() #
To clear all of cookies
clearCookie(): void