Class: HTTPClient::Header

Inherits:
Object show all
Defined in:
lib/rwd/net.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(header) ⇒ Header

Returns a new instance of Header.



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/rwd/net.rb', line 259

def initialize(header)
  @header	= {}

  if not header.nil?
    firstline, rest	= header.split(/\r*\n/, 2)

    @protocol, @code, @text	= firstline.split(/  */, 3)

    @code	= @code.to_i

    if not rest.nil?
      rest.split(/\r*\n/).each do |line|
        key, value	= line.split(/ /, 2)
        @header[key.sub(/:$/, "").downcase]	= value
      end
    end
  end
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



256
257
258
# File 'lib/rwd/net.rb', line 256

def code
  @code
end

#headerObject (readonly)

Returns the value of attribute header.



254
255
256
# File 'lib/rwd/net.rb', line 254

def header
  @header
end

#protocolObject (readonly)

Returns the value of attribute protocol.



255
256
257
# File 'lib/rwd/net.rb', line 255

def protocol
  @protocol
end

#textObject (readonly)

Returns the value of attribute text.



257
258
259
# File 'lib/rwd/net.rb', line 257

def text
  @text
end

Instance Method Details

#to_sObject



278
279
280
281
282
283
284
285
286
287
288
# File 'lib/rwd/net.rb', line 278

def to_s
  res	= ""

  res << "%s %s %s\n" % [@protocol, @code, @text]

  @header.each do |k, v|
    res << "%s=%s\n" % [k, v]
  end

  return res
end