Skip to content

Commit 4edcd5c

Browse files
committed
Merge branch 'master' of github.com:SegmentFault/node-tiny-http
Conflicts: build/request.js
2 parents d303862 + bc7d3bb commit 4edcd5c

File tree

7 files changed

+35
-31
lines changed

7 files changed

+35
-31
lines changed

build/http.js

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/request.js

Lines changed: 6 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/response.js

Lines changed: 3 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-tiny-http",
3-
"version": "1.3.4",
3+
"version": "1.3.5",
44
"description": "A tiny node.js http framework",
55
"main": "build/http.js",
66
"scripts": {

src/http.coffee

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ class Http
4949
# static file method
5050
assets: (path, dir) ->
5151
@routerInstance.register 'GET', (path.replace /\/+$/g, '') + '/%path', (done) ->
52-
done 'file', dir + '/' + ((@request.get 'path').replace /\.{2,}/g, '')
52+
parts = []
53+
path = @request.get 'path'
54+
55+
for val in path.split '/'
56+
parts.push val if not val.match /^\.+$/
57+
58+
done 'file', dir + '/' + (parts.join '/')
5359
.raw()
5460

5561

src/request.coffee

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@ QueryString = require 'querystring'
66

77
class Request
88

9-
options = {}
10-
119
mergeParams = (source, target) ->
1210
for k, v of target
1311
source[k] = v
1412

1513

16-
constructor: (@req, opt, cb) ->
14+
constructor: (@req, @options, cb) ->
1715
parts = Url.parse @req.url, yes
18-
options = opt
1916

2017
@method = @req.method.toUpperCase()
2118
@uri = parts.href
@@ -64,18 +61,18 @@ class Request
6461
defaults = ['x-real-ip', 'x-forwarded-for', 'client-ip']
6562

6663
if not @$ip?
67-
if options.ipHeader?
68-
@$ip = @header options.ipHeader, @req.socket.remoteAddress
64+
if @options.ipHeader?
65+
@$ip = @header @options.ipHeader, @req.socket.remoteAddress
6966
else
67+
@$ip = @req.socket.remoteAddress
68+
7069
for key in defaults
7170
val = @header key
7271

7372
if val?
7473
@$ip = val
7574
break
7675

77-
@$ip = @req.socket.remoteAddress
78-
7976
@$ip
8077

8178

src/response.coffee

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ patchOriginalResponse = (res) ->
1818

1919
class Response
2020

21-
options = {}
2221

23-
24-
constructor: (@res, req, opt) ->
22+
constructor: (@res, req, @options) ->
2523

2624
@$statusCode = 200
2725
@$headers =
@@ -31,10 +29,9 @@ class Response
3129
@$stream = null
3230
@$content = null
3331

34-
options = opt
3532
@responded = no
3633

37-
if opt.compression
34+
if @options.compression
3835
acceptEncoding = req.headers['accept-encoding']
3936

4037
if acceptEncoding?

0 commit comments

Comments
 (0)