rack-mogilefs 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/HISTORY.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.1.3 (2010-09-10)
2
+
3
+ * Depend on rack/mime instead of mime-types
4
+ * Add Content-Length header
5
+
1
6
  ## 0.1.2 (2010-09-09)
2
7
 
3
8
  * Add a way to customize mapping of PATH_INFO to MogileFS keys
data/README.md CHANGED
@@ -73,4 +73,3 @@ and initialize a MogileFS client like this:
73
73
  You can override this by passing in a MogileFS client of your own:
74
74
 
75
75
  Rack::MogileFS::Endpoint.new :client => MyMogileFSClient.new
76
-
data/lib/rack/mogilefs.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'mogilefs'
2
- require 'mime/types'
2
+ require 'rack/mime'
3
+ require 'rack/utils'
3
4
 
4
5
  module Rack
5
6
  class MogileFS
@@ -15,7 +15,12 @@ module Rack
15
15
  def call(env)
16
16
  path = key_for_path(env['PATH_INFO'].dup)
17
17
  data = client.get_file_data(path)
18
- [ 200, { "Content-Type" => content_type(path) }, [ data ] ]
18
+ size = Utils.bytesize(data).to_s
19
+
20
+ [ 200, {
21
+ "Content-Type" => content_type(path),
22
+ "Content-Length" => size
23
+ }, [data] ]
19
24
  rescue ::MogileFS::Backend::UnknownKeyError => e
20
25
  [ 404, { "Content-Type" => "text/html" }, [e.message] ]
21
26
  rescue ::MogileFS::UnreachableBackendError => e
@@ -30,11 +35,12 @@ module Rack
30
35
  @options[:mapper].respond_to?(:call) ? @options[:mapper].call(path) : path
31
36
  end
32
37
 
33
- def content_type(path_info)
34
- ext = path_info.split(".").last
35
- MIME::Types.type_for(ext).first.content_type
36
- rescue
37
- @options[:default_content_type]
38
+ def content_type(path)
39
+ Mime.mime_type(::File.extname(path), @options[:default_content_type])
40
+ end
41
+
42
+ def content_length(data)
43
+ Utils.bytesize(data)
38
44
  end
39
45
 
40
46
  def client
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-mogilefs
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ben Marini
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-09 00:00:00 -07:00
18
+ date: 2010-09-10 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -35,18 +35,19 @@ dependencies:
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency
38
- name: mime-types
38
+ name: rack
39
39
  prerelease: false
40
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - "="
43
+ - - ">="
44
44
  - !ruby/object:Gem::Version
45
- hash: 47
45
+ hash: 19
46
46
  segments:
47
47
  - 1
48
- - 16
49
- version: "1.16"
48
+ - 1
49
+ - 0
50
+ version: 1.1.0
50
51
  type: :runtime
51
52
  version_requirements: *id002
52
53
  - !ruby/object:Gem::Dependency