0.5.8 • Published 10 years ago
proxy-cache-file v0.5.8
proxy-cache-file
Proxy and cache a file and related headers
Installation
This module is installed via npm:
npm i proxy-cache-file --save
Example Usage
Setup
var proxyCacheFile = require('proxy-cache-file')
proxyCacheFile({ dir: 0 }) // disable file cache
proxyCacheFile({ dir: '/tmp' }) // temporary folder used for disk cache, default
Get proxy entry via url
string
var proxyCacheFile = require('./')({ dir: './tmp' })
var url = 'https://cdnjs.cloudflare.com/ajax/libs/1140/2.0/1140.min.css'
proxyCacheFile(url, function(err, proxyData) {
if (err) throw err
console.log(proxyData)
})
{
"headers": [
{
"name": "content-type",
"value": "text/css"
}
],
"data": [104, 116, 109, ... 120, 125, 125],
"isBuffer": true
}
Get proxy entry gzipped
proxyCacheFile({ url: url, gzip: true }, function(err, proxyData) {
if (err) {
console.error(err)
} else {
console.log(JSON.stringify(proxyData, null, 2))
}
})
{
"headers": [
{
"name": "content-type",
"value": "text/css"
},
{
"name": "content-encoding",
"value": "gzip"
}
],
"data": [115, 40, 204, ... 6, 0, 0],
"isBuffer": true
}
Then run again cache hit returns:
{
"headers": [
{
"name": "content-type",
"value": "text/css"
},
{
"name": "content-encoding",
"value": "gzip"
}
],
"data": {
"_readableState": {
"highWaterMark": 65536,
...
"encoding": null
},
"readable": true,
"domain": null,
"_events": {},
"_maxListeners": 10,
"path": "tmp/12decaf9245f4bf9f86ce8272481ee1f",
"fd": null,
"flags": "r",
"mode": 438,
"autoClose": true
}
}
Returned proxyData:
{ headers: [], data: Buffer || Stream, isBuffer: boolean }
- headers: an array of {name: 'header-name', value: 'header-value'}
- data: Buffer or Stream of data ready for express, ie
res.send(proxyData.data)
- isBuffer: true if
proxyData.data
is a Buffer
Data is returned as a Buffer during non-cached proxy requests
Rights
Copyright (C) 2015 by Yieme, License: MIT
0.5.8
10 years ago
0.5.7
10 years ago
0.5.6
10 years ago
0.5.4
10 years ago
0.5.3
10 years ago
0.5.2
10 years ago
0.5.1
10 years ago
0.4.6
10 years ago
0.4.5
10 years ago
0.4.4
10 years ago
0.4.3
10 years ago
0.4.2
10 years ago
0.4.1
10 years ago
0.3.1
10 years ago
0.2.3
10 years ago
0.2.2
10 years ago
0.2.1
10 years ago
0.1.3
10 years ago
0.1.1
10 years ago
0.1.0
10 years ago