Skip to content

Commit 02a6aad

Browse files
committed
Fix encoding catchass, add readme
1 parent 409c869 commit 02a6aad

File tree

3 files changed

+47
-6
lines changed

3 files changed

+47
-6
lines changed

README.md

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,46 @@
1-
# Work in Progress... DON'T USE THIS! No. Not Yet.
2-
31
# Webmachine NodeJS [![travis](https://secure.travis-ci.org/coderoshi/webmachine-nodejs.png)](http://travis-ci.org/coderoshi/webmachine-nodejs)
42

5-
This is a Webmachine toolkit for NodeJS, inspired by the original Erlang Webmachine and Ruby port.
3+
This is a Webmachine toolkit for NodeJS, inspired by the original Erlang [Webmachine](https://github.com/basho/webmachine/wiki) and [Ruby port](https://github.com/seancribbs/webmachine-ruby). Thanks also to Nodemachine for some test scenarios.
4+
5+
## Usage
6+
7+
The easiest way to get started is to include `webmachine` npm project into `package.json`.
8+
9+
```json
10+
{
11+
"name": "wmtest",
12+
"version": "0.0.1",
13+
"dependencies": {
14+
"webmachine" : "~>0.0.3"
15+
}
16+
}
17+
```
18+
19+
From there, create a webmachine resource. The same functions that can be overridden in other webmachine implementations can be done here, the only difference is that the function names are a JavaScripty camel case style, rather than underscore seperated.
20+
21+
Here is a simple app that adds a root (`"/"`) resource to the service running on port `3000`. You can add as many resources as you need. Routes can be an array, and also conform to Sinatra rules (eg. `/users/:uid`).
22+
23+
```javascript
24+
var wm = require('webmachine');
25+
26+
var root = {
27+
route: "/",
28+
toHtml: function(req, res, next) {
29+
next("<html><h1>Hello World</h1></html>");
30+
}
31+
};
32+
wm.add(root);
33+
wm.start(3000, '0.0.0.0');
34+
```
35+
36+
If you run into issues, you can trace the output. It will present a list of steps taken to arrive at the given response.
37+
38+
```
39+
wm.trace(true);
40+
```
41+
42+
The output might not make a lot of sense without this chart, the steps are the decision points.
43+
44+
<a href="https://raw.github.com/wiki/basho/webmachine/images/http-headers-status-v3.png">
45+
<img src='https://raw.github.com/wiki/basho/webmachine/images/http-headers-status-v3.png' width=550 align=center>
46+
</a>

lib/fsm.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,9 @@ FSM.prototype.doChooseEncoding = function(provided, encoding) {
252252
match = (accept === "*") || (provided[accept] != null);
253253
if (match) accepted_encoding = accept;
254254
}
255-
// TODO: this is likely wrong
255+
// TODO: this is a lame catchall
256256
if(accepted_encoding === '*') {
257-
accepted_encoding = "identity";
257+
accepted_encoding = _.first(_.keys(provided));
258258
}
259259
return accepted_encoding;
260260
};

test/encoding-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ vows.describe('FSM Encoding').addBatch({
1313
var resource = new Resource(root);
1414
var fsm = new Fsm(resource);
1515
var identityFunc = function(x){ return x; };
16-
var provided = {"deflate":identityFunc,"identity":identityFunc};
16+
var provided = {"identity":identityFunc};
1717
var acceptencoding = '*';
1818
var encoding = fsm.doChooseEncoding(provided, acceptencoding);
1919
this.callback(true, encoding);

0 commit comments

Comments
 (0)