Skip to content

Commit

Permalink
Cleaning unused spaces, adding content to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
pfleidi committed Oct 26, 2010
1 parent 4c82b45 commit 4e3bbf4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ Usage

A working example:

// simple example
var sys = require('sys'),
wwdude = require('node-wwwdude');

Expand All @@ -58,13 +57,15 @@ API

### wwwdude.createClient([options])

Creates a new client object with predefined options for each request made with this instance.

#### options hash

* _encoding_ content encoding. e.g. binary or utf8. Default is utf8.
* _logger_ the logger you want to use. Default is an internal logger using sys.log.
* _headers_ a hash with the headers you want to use for each request.

This calls returns a Request object. On that request object you can call methods for each supported HTTP verb.
The createClient call returns a Request object. On that request object you can call methods for each supported HTTP verb.

### client.get(url[, customHeaders])

Expand All @@ -90,7 +91,7 @@ Creates a HTTP HEAD request

The customHeaders hash contains a set of HTTP headers which should be added to a request. They are optional. A working example would be:

customHeaders = { 'User-Agent': 'Foo', 'Accept: 'text/html' };
customHeaders = { 'User-Agent': 'Foo', 'Accept': 'text/html' };

### Listeners

Expand Down Expand Up @@ -166,13 +167,14 @@ To run the unit tests, nodeunit and log4js-node are required. You can install th

There's a Makefile to run the tests:

make test
make test

TODO:
-----

* Get rid of logging statements
* Add plugin infrastructure
* More configurable redirect following (set max. redirect count, disable following of redirect)
* Pluggable logger support
* Pluggable support for transparent content decoders

Expand Down
12 changes: 6 additions & 6 deletions lib/wwwdude.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* httpclient.js a thin abstraction layer for http client stuff
*
* @author pfleidi
* @author pfleidi
*
* Copyright(c) 2010 Sven Pfleiderer.
* MIT Licensed
Expand Down Expand Up @@ -84,7 +84,7 @@ exports.createClient = function createClient(options) {

var logger = options.logger || defaultLogger,
encoding = options.encoding || 'utf8',
clientHeaders = Meta.mergeAttributes(defaultHeaders, options.headers);
clientHeaders = Meta.mergeAttributes(defaultHeaders, options.headers);

function Request(method, url, options) {
var self = this,
Expand Down Expand Up @@ -144,13 +144,13 @@ exports.createClient = function createClient(options) {
this._respond(statusCodes[code.toString()], data, response);

if (code >= 400) {
logger.error("Error: status code " + response.statusCode);
logger.error("Error: status code " + response.statusCode);
this._respond('error', data, response);
} else if (code >= 300) {
this._respond('redirect', data, response);
if (code === 301 || code === 302) {
this._redirect(response);
}
}
} else if (code >= 200) {
logger.info('Transfer complete');
this._respond('success', data, response);
Expand Down Expand Up @@ -184,7 +184,7 @@ exports.createClient = function createClient(options) {

Request.prototype._redirect = function (response) {
var nextLocation = Url.resolve(this.url, response.headers.location);
this.options.originalRequest = this;
this.options.originalRequest = this;
(new Request(this.method, nextLocation, this.options).send());
logger.info("Next URL: " + nextLocation);
};
Expand All @@ -200,7 +200,7 @@ exports.createClient = function createClient(options) {
/**
* Parse an URL an add some needed properties
*
* @param {String} url
* @param {String} url
* @return {Object}
* @api private
*/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ "name" : "node-wwwdude",
{ "name" : "wwwdude",
"description" : "Simple to use HTTP library on top of the built in libs of node.js",
"tags" : ["http", "simple", "util", "rest", "utility"],
"version" : "0.0.1",
Expand Down

0 comments on commit 4e3bbf4

Please sign in to comment.