Permalink
Browse files

readme update

  • Loading branch information...
andris9
andris9 committed Oct 14, 2011
1 parent ef375b2 commit a13ba38324d54f097eb24067608a085d2634e373
Showing with 57 additions and 10 deletions.
  1. +49 −2 README.md
  2. +8 −8 fetch.js
View
@@ -10,9 +10,57 @@ Fetch url contents. Supports gzipped content for quicker download, redirects (wi
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
-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,
fs = require("fs"),
@@ -21,7 +69,6 @@ Stream URL contents directly to file
out = fs.createWriteStream('file.html');
new FetchStream("http://www.example.com/index.php").pipe(out);
-
## License
BSD
View
@@ -8,25 +8,25 @@ var http = require("http"),
/*
-headers: {}
-payload: txt
-
-maxresponse (100kB)
-headers: {}
-maxredirects: 10
-
-
maxRedirects : 10
disableRedirects : false
headers: {}
maxResponseLength : Infinity
method: GET
payload: str
+disableGzip: false
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;
function FetchStream(url, options){

0 comments on commit a13ba38

Please sign in to comment.