Skip to content

Commit

Permalink
readme update
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Oct 14, 2011
1 parent ef375b2 commit a13ba38
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 10 deletions.
51 changes: 49 additions & 2 deletions README.md
Expand Up @@ -10,9 +10,57 @@ Fetch url contents. Supports gzipped content for quicker download, redirects (wi


See test.js for a complete example See test.js for a complete example


## Headers

Request headers can be set with `options.headers`

options = {
headers:{
"X-My-Header": "This is a custom header field"
}
}

## User-Agent
User-Agent value can be set with `options.headers['User-Agent']` value. Defaults to `"FetchStream"`

options = {
headers: {
"User-Agent": "MyUseragent/1.0"
}
}

## Cookies
Cookies can be set with `options.cookies` which takes an array with cookie definitions

options = {
cookie: ["name=value", "key=value; path=/; secure"]
}

**NB** Do not set cookie field directly in request header as it will be overwritten.

## Redirects

Redirects are on by default, use `options.disableRedirects` to disable. Maximum redirect count can be set with `options.maxRedirects` (defaults to 10)

options = {
disableRedirects: true
}

options = {
maxRedirects: 100
}

## Disable Gzip support

Gzip and Deflate support is automatically on. This is problematic in Node v0.5.9 and below since Zlib on these versions is buggy and tends to yield in error.

options = {
disableGzip: true
}

## Piping to file ## Piping to file


Stream URL contents directly to file `FetchStream` is a readable Stream object and thus can be piped. For example stream URL contents directly to a file:


var FetchStream = require("./fetch").FetchStream, var FetchStream = require("./fetch").FetchStream,
fs = require("fs"), fs = require("fs"),
Expand All @@ -21,7 +69,6 @@ Stream URL contents directly to file
out = fs.createWriteStream('file.html'); out = fs.createWriteStream('file.html');
new FetchStream("http://www.example.com/index.php").pipe(out); new FetchStream("http://www.example.com/index.php").pipe(out);



## License ## License


BSD BSD
16 changes: 8 additions & 8 deletions fetch.js
Expand Up @@ -8,25 +8,25 @@ var http = require("http"),


/* /*
headers: {}
payload: txt
maxresponse (100kB)
headers: {}
maxredirects: 10
maxRedirects : 10 maxRedirects : 10
disableRedirects : false disableRedirects : false
headers: {} headers: {}
maxResponseLength : Infinity maxResponseLength : Infinity
method: GET method: GET
payload: str payload: str
disableGzip: false
cookies: ['name=val'] cookies: ['name=val']
setEncoding: true | utf-8 | latin-1 jne
*/ */


//TODO:
// - meta infosse faili nimi, juhul kui tegu downloadiga
// - wrapper fetch(url, callback)
// - wrapperile options.setEncoding = true | "UTF-8"

exports.FetchStream = FetchStream; exports.FetchStream = FetchStream;


function FetchStream(url, options){ function FetchStream(url, options){
Expand Down

0 comments on commit a13ba38

Please sign in to comment.