Method: Warc::Record#initialize
- Defined in:
- lib/warc/record.rb
#initialize(h = {}, content = nil) ⇒ Record
Returns a new instance of Record.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/warc/record.rb', line 7 def initialize(h={},content=nil) @content=content case h when Hash @header = Header.new(self,h) when WEBrick::HTTPResponse @header = Header.new(self) @header["WARC-Type"] = "response" @header["WARC-Target-URI"] = h.request_uri.to_s @header["Content-Type"] = "application/http;msgtype=response" #@header["WARC-IP-Address"] body,crfl = String.new,"\r\n" body << h.status_line h.header.each do |k,v| body << "#{k}: #{v}" + crfl end body << crfl + h.body self.content = body self.header.block_digest @header["WARC-Payload-Digest"] = self.header.compute_digest(h.body) end end |