Class: SOAP::MIMEMessage::Headers

Inherits:
Hash show all
Defined in:
lib/soap/mimemessage.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Hash

#key

Class Method Details

.parse(str) ⇒ Object



46
47
48
# File 'lib/soap/mimemessage.rb', line 46

def self.parse(str)
  new.parse(str)
end

Instance Method Details

#add(key, value) ⇒ Object



93
94
95
96
97
98
99
# File 'lib/soap/mimemessage.rb', line 93

def add(key, value)
  if key != nil and value != nil
	header = parse_rhs(value)
	header.key = key
	self[key.downcase] = header
  end
end

#parse(str) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/soap/mimemessage.rb', line 50

def parse(str)
  header_cache = nil
  str.each do |line|
	case line
	when /^\A[^\: \t]+:\s*.+$/
	  parse_line(header_cache) if header_cache
	  header_cache = line.sub(/\r?\n\z/, '')
	when /^\A\s+(.*)$/
	  # a continuous line at the beginning line crashes here.
	  header_cache << line
	else
	  raise RuntimeError.new("unexpected header: #{line.inspect}")
	end
  end
  parse_line(header_cache) if header_cache
  self
end

#parse_line(line) ⇒ Object



68
69
70
71
72
73
74
75
76
# File 'lib/soap/mimemessage.rb', line 68

def parse_line(line)
  if /^\A([^\: \t]+):\s*(.+)\z/ =~ line
	header = parse_rhs($2.strip)
	header.key = $1.strip
	self[header.key.downcase] = header
  else
	raise RuntimeError.new("unexpected header line: #{line.inspect}")
  end
end

#parse_rhs(str) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/soap/mimemessage.rb', line 78

def parse_rhs(str)
  a = str.split(/;+\s+/)
  header = Header.new
  header.str = str
  header.root = a.shift
  a.each do |pair|
	if pair =~ /(\w+)\s*=\s*"?([^"]+)"?/
	  header[$1.downcase] = $2
	else
	  raise RuntimeError.new("unexpected header component: #{pair.inspect}")
	end
  end
  header
end

#to_sObject



101
102
103
104
105
# File 'lib/soap/mimemessage.rb', line 101

def to_s
  self.values.collect { |hdr|
	hdr.to_s
  }.join("\r\n")
end