server_here 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f556a7a5db2a8c1df6ceeb49ae010c8eda485f35
4
- data.tar.gz: d463be23cb17c43e818d2a54900e6f37ee7c4357
3
+ metadata.gz: a2f3d06db25ba328e041b309d0cb6a22af5a2738
4
+ data.tar.gz: 749277692c101fa3a364d1d8e0be523bcbf2472d
5
5
  SHA512:
6
- metadata.gz: 1f3b34584e0df26d3d3e68a49bd668ac5607e6eb4245e132e97e6c1e87169be4b08ec1b12de664736f3f769f5e8c7bc8dbcbc8ebc7cf467d6b5ac2d8f30cce74
7
- data.tar.gz: fc3be6fd487a25be02ca38bb08f005a6ac0be59adc774fb99e48a1a4429d626afaea7d1a68107fa33c7da4e8d85045e83f5afd1dbf581a2197bfbbecdea4abca
6
+ metadata.gz: b930889fa163f7e21fff8cae858af3d433a197ce59b289a65ea2fb5ebccddb56527e51b5458426ad900359c13e2adc2962c768746b7cf48438b0d49e359845be
7
+ data.tar.gz: 97e5c9d63e9f33055e45dcdf551aa4150b7a1b5bf85861913ac1d4320ab4a0eb28b965c4a54b05494afc44edf7fe4765f7ce604e97c7c8ec0eb3539f8234f029
@@ -0,0 +1,197 @@
1
+ module ServerHere
2
+ class FileWrapper
3
+
4
+ ContentTypeMap ={
5
+ "323"=> "text/h323",
6
+ "*"=> "application/octet-stream",
7
+ "acx"=> "application/internet-property-stream",
8
+ "ai"=> "application/postscript",
9
+ "aif"=> "audio/x-aiff",
10
+ "aifc"=> "audio/x-aiff",
11
+ "aiff"=> "audio/x-aiff",
12
+ "asf"=> "video/x-ms-asf",
13
+ "asr"=> "video/x-ms-asf",
14
+ "asx"=> "video/x-ms-asf",
15
+ "au"=> "audio/basic",
16
+ "avi"=> "video/x-msvideo",
17
+ "axs"=> "application/olescript",
18
+ "bas"=> "text/plain",
19
+ "bcpio"=> "application/x-bcpio",
20
+ "bin"=> "application/octet-stream",
21
+ "bmp"=> "image/bmp",
22
+ "c"=> "text/plain",
23
+ "cat"=> "application/vnd.ms-pkiseccat",
24
+ "cdf"=> "application/x-netcdf",
25
+ "cer"=> "application/x-x509-ca-cert",
26
+ "class"=> "application/octet-stream",
27
+ "clp"=> "application/x-msclip",
28
+ "cmx"=> "image/x-cmx",
29
+ "cod"=> "image/cis-cod",
30
+ "cpio"=> "application/x-cpio",
31
+ "crd"=> "application/x-mscardfile",
32
+ "crl"=> "application/pkix-crl",
33
+ "crt"=> "application/x-x509-ca-cert",
34
+ "csh"=> "application/x-csh",
35
+ "css"=> "text/css",
36
+ "dcr"=> "application/x-director",
37
+ "der"=> "application/x-x509-ca-cert",
38
+ "dir"=> "application/x-director",
39
+ "dll"=> "application/x-msdownload",
40
+ "dms"=> "application/octet-stream",
41
+ "doc"=> "application/msword",
42
+ "dot"=> "application/msword",
43
+ "dvi"=> "application/x-dvi",
44
+ "dxr"=> "application/x-director",
45
+ "eps"=> "application/postscript",
46
+ "etx"=> "text/x-setext",
47
+ "evy"=> "application/envoy",
48
+ "exe"=> "application/octet-stream",
49
+ "fif"=> "application/fractals",
50
+ "flr"=> "x-world/x-vrml",
51
+ "gif"=> "image/gif",
52
+ "gtar"=> "application/x-gtar",
53
+ "gz"=> "application/x-gzip",
54
+ "h"=> "text/plain",
55
+ "hdf"=> "application/x-hdf",
56
+ "hlp"=> "application/winhlp",
57
+ "hqx"=> "application/mac-binhex40",
58
+ "hta"=> "application/hta",
59
+ "htc"=> "text/x-component",
60
+ "htm"=> "text/html",
61
+ "html"=> "text/html",
62
+ "htt"=> "text/webviewhtml",
63
+ "ico"=> "image/x-icon",
64
+ "ief"=> "image/ief",
65
+ "iii"=> "application/x-iphone",
66
+ "ins"=> "application/x-internet-signup",
67
+ "isp"=> "application/x-internet-signup",
68
+ "jfif"=> "image/pipeg",
69
+ "jpe"=> "image/jpeg",
70
+ "jpeg"=> "image/jpeg",
71
+ "jpg"=> "image/jpeg",
72
+ "js"=> "application/x-javascript",
73
+ "latex"=> "application/x-latex",
74
+ "lha"=> "application/octet-stream",
75
+ "lsf"=> "video/x-la-asf",
76
+ "lsx"=> "video/x-la-asf",
77
+ "lzh"=> "application/octet-stream",
78
+ "m13"=> "application/x-msmediaview",
79
+ "m14"=> "application/x-msmediaview",
80
+ "m3u"=> "audio/x-mpegurl",
81
+ "man"=> "application/x-troff-man",
82
+ "mdb"=> "application/x-msaccess",
83
+ "me"=> "application/x-troff-me",
84
+ "mht"=> "message/rfc822",
85
+ "mhtml"=> "message/rfc822",
86
+ "mid"=> "audio/mid",
87
+ "mny"=> "application/x-msmoney",
88
+ "mov"=> "video/quicktime",
89
+ "movie"=> "video/x-sgi-movie",
90
+ "mp2"=> "video/mpeg",
91
+ "mp3"=> "audio/mpeg",
92
+ "mpa"=> "video/mpeg",
93
+ "mpe"=> "video/mpeg",
94
+ "mpeg"=> "video/mpeg",
95
+ "mpg"=> "video/mpeg",
96
+ "mpp"=> "application/vnd.ms-project",
97
+ "mpv2"=> "video/mpeg",
98
+ "ms"=> "application/x-troff-ms",
99
+ "msg"=> "application/vnd.ms-outlook",
100
+ "mvb"=> "application/x-msmediaview",
101
+ "nc"=> "application/x-netcdf",
102
+ "nws"=> "message/rfc822",
103
+ "oda"=> "application/oda",
104
+ "p10"=> "application/pkcs10",
105
+ "p12"=> "application/x-pkcs12",
106
+ "p7b"=> "application/x-pkcs7-certificates",
107
+ "p7c"=> "application/x-pkcs7-mime",
108
+ "p7m"=> "application/x-pkcs7-mime",
109
+ "p7r"=> "application/x-pkcs7-certreqresp",
110
+ "p7s"=> "application/x-pkcs7-signature",
111
+ "pbm"=> "image/x-portable-bitmap",
112
+ "pdf"=> "application/pdf",
113
+ "pfx"=> "application/x-pkcs12",
114
+ "pgm"=> "image/x-portable-graymap",
115
+ "pko"=> "application/ynd.ms-pkipko",
116
+ "pma"=> "application/x-perfmon",
117
+ "pmc"=> "application/x-perfmon",
118
+ "pml"=> "application/x-perfmon",
119
+ "pmr"=> "application/x-perfmon",
120
+ "pmw"=> "application/x-perfmon",
121
+ "pnm"=> "image/x-portable-anymap",
122
+ "pot"=> "application/vnd.ms-powerpoint",
123
+ "ppm"=> "image/x-portable-pixmap",
124
+ "pps"=> "application/vnd.ms-powerpoint",
125
+ "ppt"=> "application/vnd.ms-powerpoint",
126
+ "prf"=> "application/pics-rules",
127
+ "ps"=> "application/postscript",
128
+ "pub"=> "application/x-mspublisher",
129
+ "qt"=> "video/quicktime",
130
+ "ra"=> "audio/x-pn-realaudio",
131
+ "ram"=> "audio/x-pn-realaudio",
132
+ "ras"=> "image/x-cmu-raster",
133
+ "rgb"=> "image/x-rgb",
134
+ "rmi"=> "audio/mid",
135
+ "roff"=> "application/x-troff",
136
+ "rtf"=> "application/rtf",
137
+ "rtx"=> "text/richtext",
138
+ "scd"=> "application/x-msschedule",
139
+ "sct"=> "text/scriptlet",
140
+ "setpay"=> "application/set-payment-initiation",
141
+ "setreg"=> "application/set-registration-initiation",
142
+ "sh"=> "application/x-sh",
143
+ "shar"=> "application/x-shar",
144
+ "sit"=> "application/x-stuffit",
145
+ "snd"=> "audio/basic",
146
+ "spc"=> "application/x-pkcs7-certificates",
147
+ "spl"=> "application/futuresplash",
148
+ "src"=> "application/x-wais-source",
149
+ "sst"=> "application/vnd.ms-pkicertstore",
150
+ "stl"=> "application/vnd.ms-pkistl",
151
+ "stm"=> "text/html",
152
+ "sv4cpio"=> "application/x-sv4cpio",
153
+ "sv4crc"=> "application/x-sv4crc",
154
+ "svg"=> "image/svg+xml",
155
+ "swf"=> "application/x-shockwave-flash",
156
+ "t"=> "application/x-troff",
157
+ "tar"=> "application/x-tar",
158
+ "tcl"=> "application/x-tcl",
159
+ "tex"=> "application/x-tex",
160
+ "texi"=> "application/x-texinfo",
161
+ "texinfo"=> "application/x-texinfo",
162
+ "tgz"=> "application/x-compressed",
163
+ "tif"=> "image/tiff",
164
+ "tiff"=> "image/tiff",
165
+ "tr"=> "application/x-troff",
166
+ "trm"=> "application/x-msterminal",
167
+ "tsv"=> "text/tab-separated-values",
168
+ "txt"=> "text/plain",
169
+ "uls"=> "text/iuls",
170
+ "ustar"=> "application/x-ustar",
171
+ "vcf"=> "text/x-vcard",
172
+ "vrml"=> "x-world/x-vrml",
173
+ "wav"=> "audio/x-wav",
174
+ "wcm"=> "application/vnd.ms-works",
175
+ "wdb"=> "application/vnd.ms-works",
176
+ "wks"=> "application/vnd.ms-works",
177
+ "wmf"=> "application/x-msmetafile",
178
+ "wps"=> "application/vnd.ms-works",
179
+ "wri"=> "application/x-mswrite",
180
+ "wrl"=> "x-world/x-vrml",
181
+ "wrz"=> "x-world/x-vrml",
182
+ "xaf"=> "x-world/x-vrml",
183
+ "xbm"=> "image/x-xbitmap",
184
+ "xla"=> "application/vnd.ms-excel",
185
+ "xlc"=> "application/vnd.ms-excel",
186
+ "xlm"=> "application/vnd.ms-excel",
187
+ "xls"=> "application/vnd.ms-excel",
188
+ "xlt"=> "application/vnd.ms-excel",
189
+ "xlw"=> "application/vnd.ms-excel",
190
+ "xof"=> "x-world/x-vrml",
191
+ "xpm"=> "image/x-xpixmap",
192
+ "xwd"=> "image/x-xwindowdump",
193
+ "z"=> "application/x-compress",
194
+ "zip"=> "application/zip"
195
+ }
196
+ end
197
+ end
@@ -15,11 +15,6 @@ module ServerHere
15
15
 
16
16
  file = FileWrapper.new path
17
17
 
18
- if_mod_since = req.get_header 'HTTP_IF_MODIFIED_SINCE'
19
- if if_mod_since and file.last_mod == if_mod_since
20
- return [304, {}, []]
21
- end
22
-
23
18
  header = {
24
19
  'Content-Type' => file.content_type,
25
20
  'Last-Modified' => file.last_mod
@@ -1,3 +1,5 @@
1
+ require 'server_here/content_type_map'
2
+
1
3
  module ServerHere
2
4
  class FileWrapper
3
5
  def initialize file
@@ -5,7 +7,7 @@ module ServerHere
5
7
  end
6
8
 
7
9
  def last_mod
8
- @last_mod ||= File.mtime(@f).strftime '%a, %d %b %Y %T GMT'
10
+ @last_mod ||= File.mtime(@f).rfc2822
9
11
  end
10
12
 
11
13
  def ext
@@ -13,11 +15,11 @@ module ServerHere
13
15
  end
14
16
 
15
17
  def content_type
16
- 'text/' + (%w{html css}.include?(ext) ? ext : 'plain')
18
+ ContentTypeMap[ext] || 'text/plain'
17
19
  end
18
20
 
19
21
  def to_body
20
- [File.read(@f)]
22
+ File.new(@f)
21
23
  end
22
24
  end
23
25
  end
@@ -1,3 +1,3 @@
1
1
  module ServerHere
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/server_here.rb CHANGED
@@ -11,8 +11,9 @@ Dir[lib].each do |f|
11
11
  end
12
12
 
13
13
  module ServerHere
14
- App = Rack::Builder.new {
14
+ App = Rack::Builder.app {
15
15
  use Rack::ContentLength
16
+ use Rack::ConditionalGet
16
17
  use EnvInspector
17
18
  run Core.new
18
19
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: server_here
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ken
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-12 00:00:00.000000000 Z
11
+ date: 2016-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -71,6 +71,7 @@ files:
71
71
  - bin/server_here
72
72
  - bin/setup
73
73
  - lib/server_here.rb
74
+ - lib/server_here/content_type_map.rb
74
75
  - lib/server_here/core.rb
75
76
  - lib/server_here/env_inspector.rb
76
77
  - lib/server_here/file_wrapper.rb
@@ -97,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
98
  version: '0'
98
99
  requirements: []
99
100
  rubyforge_project:
100
- rubygems_version: 2.6.7
101
+ rubygems_version: 2.4.8
101
102
  signing_key:
102
103
  specification_version: 4
103
104
  summary: try to implement a static file server