Class: SOAP::MIMEMessage::Headers

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(str) ⇒ Object



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

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

Instance Method Details

#add(key, value) ⇒ Object



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

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



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

def parse(str)
  header_cache = nil
  str = str.lines if str.respond_to?(:lines) # RubyJedi: compatible with Ruby 1.8.6 and above      
  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



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

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



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

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



103
104
105
106
107
# File 'lib/soap/mimemessage.rb', line 103

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