public
Rubygem
Fork of jmhodges/rfeedparser
Description: rFeedParser is a translation of the Universal Feed Parser from Python into Ruby. It has nearly the exact same behavior.
Homepage: http://rfeedparser.rubyforge.org
Clone URL: git://github.com/technomancy/rfeedparser.git
fixed bug in Mongrel::DirHandler that caused a 220 status code to be lost 
and replaced with 200.  corrected the 220.xml test case to have the proper 
status code as well
Jeff Hodges (author)
Mon Oct 22 03:10:58 -0700 2007
commit  488028ad4531f643ec2e72783bd09fa8bc57c405
tree    8dd4e520df914fc56c08d209d5d906dc62ff62f4
parent  363262b0e59b37e9e0fa1f289c3befd4d4ce76a8
...
5
6
7
8
 
9
10
11
...
5
6
7
 
8
9
10
11
0
@@ -5,7 +5,7 @@ require 'rake/gempackagetask'
0
 
0
 spec = Gem::Specification.new do |s|
0
     s.name = "rfeedparser"
0
- s.version = "0.9.931" # Don't forget the Version in rfeedparser.rb
0
+ s.version = "0.9.94" # Don't forget the Version in rfeedparser.rb
0
     s.author = "Jeff Hodges"
0
     s.email = "jeff at somethingsimilar dot com"
0
     s.homepage = "http://rfeedparser.rubyforge.org/"
...
9
10
11
 
12
13
14
...
194
195
196
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
197
198
199
...
9
10
11
12
13
14
15
...
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
0
@@ -9,6 +9,7 @@ rescue => details
0
   STDERR.puts "Whoops, had an error with loading mongrel as a gem. Trying just 'require'. Mongrel is required for testing."
0
   require 'mongrel'
0
 end
0
+Mongrel::HTTP_STATUS_CODES[220] = "Unspecified success"
0
 
0
 def uconvert(one, two, three); FeedParser::uconvert(one, two, three); end
0
 def _ebcdic_to_ascii(one); FeedParser::_ebcdic_to_ascii(one); end
0
@@ -194,6 +195,61 @@ class FeedParserTestRequestHandler < Mongrel::DirHandler
0
       end
0
     end
0
   end
0
+
0
+ # Overriding the send_file in DirHandler for a goddamn one line bug fix.
0
+ # Holy shit does this suck. Changing `response.status = 200` to
0
+ # `response.status ||= 200`. Also, adding Mongrel:: in front of the Const
0
+ # because subclassing makes them break.
0
+ def send_file(req_path, request, response, header_only=false)
0
+
0
+ stat = File.stat(req_path)
0
+
0
+ # Set the last modified times as well and etag for all files
0
+ mtime = stat.mtime
0
+ # Calculated the same as apache, not sure how well the works on win32
0
+ etag = Mongrel::Const::ETAG_FORMAT % [mtime.to_i, stat.size, stat.ino]
0
+
0
+ modified_since = request.params[Mongrel::Const::HTTP_IF_MODIFIED_SINCE]
0
+ none_match = request.params[Mongrel::Const::HTTP_IF_NONE_MATCH]
0
+
0
+ # test to see if this is a conditional request, and test if
0
+ # the response would be identical to the last response
0
+ same_response = case
0
+ when modified_since && !last_response_time = Time.httpdate(modified_since) rescue nil : false
0
+ when modified_since && last_response_time > Time.now : false
0
+ when modified_since && mtime > last_response_time : false
0
+ when none_match && none_match == '*' : false
0
+ when none_match && !none_match.strip.split(/\s*,\s*/).include?(etag) : false
0
+ else modified_since || none_match # validation successful if we get this far and at least one of the header exists
0
+ end
0
+
0
+ header = response.header
0
+ header[Mongrel::Const::ETAG] = etag
0
+
0
+ if same_response
0
+ response.start(304) {}
0
+ else
0
+ # first we setup the headers and status then we do a very fast send on the socket directly
0
+ response.status ||= 200
0
+ header[Mongrel::Const::LAST_MODIFIED] = mtime.httpdate
0
+
0
+ # set the mime type from our map based on the ending
0
+ dot_at = req_path.rindex('.')
0
+ if dot_at
0
+ header[Mongrel::Const::CONTENT_TYPE] = MIME_TYPES[req_path[dot_at .. -1]] || @default_content_type
0
+ else
0
+ header[Mongrel::Const::CONTENT_TYPE] = @default_content_type
0
+ end
0
+
0
+ # send a status with out content length
0
+ response.send_status(stat.size)
0
+ response.send_header
0
+
0
+ if not header_only
0
+ response.send_file(req_path, stat.size < Mongrel::Const::CHUNK_SIZE * 2)
0
+ end
0
+ end
0
+ end
0
 end
0
 
0
 
...
1
2
3
4
 
5
6
7
...
1
2
3
 
4
5
6
7
0
@@ -1,7 +1,7 @@
0
 <!--
0
 Status: 220
0
 Description: return 220 status code which is unknown but successful, so interpret it as 200
0
-Expect: not bozo and len(entries) == 1 and status == "200"
0
+Expect: not bozo and len(entries) == 1 and status == "220"
0
 -->
0
 <feed xmlns="http://www.w3.org/2005/Atom">
0
 <title>Feed 220</title>

Comments

    No one has commented yet.