From 03d91590258e7cc6e27a8b0c1dc21ff93b70884a Mon Sep 17 00:00:00 2001 From: Leon Breedt Date: Sat, 16 Jul 2005 21:08:27 +0000 Subject: we should respect charset for incoming messages and not assuming incoming is always UTF-8, and only force UTF-8 for our response. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1842 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../lib/action_web_service/protocol/soap_protocol.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'actionwebservice') diff --git a/actionwebservice/lib/action_web_service/protocol/soap_protocol.rb b/actionwebservice/lib/action_web_service/protocol/soap_protocol.rb index 89f222f908..b28d57d00e 100644 --- a/actionwebservice/lib/action_web_service/protocol/soap_protocol.rb +++ b/actionwebservice/lib/action_web_service/protocol/soap_protocol.rb @@ -28,9 +28,10 @@ module ActionWebService # :nodoc: def decode_action_pack_request(action_pack_request) return nil unless soap_action = has_valid_soap_action?(action_pack_request) service_name = action_pack_request.parameters['action'] + input_encoding = parse_charset(action_pack_request.env['HTTP_CONTENT_TYPE']) protocol_options = { :soap_action => soap_action, - :charset => AWSEncoding + :charset => input_encoding } decode_request(action_pack_request.raw_post, service_name, protocol_options) end @@ -42,7 +43,7 @@ module ActionWebService # :nodoc: end def decode_request(raw_request, service_name, protocol_options={}) - envelope = SOAP::Processor.unmarshal(raw_request, :charset => AWSEncoding) + envelope = SOAP::Processor.unmarshal(raw_request, :charset => protocol_options[:charset]) unless envelope raise ProtocolError, "Failed to parse SOAP request message" end @@ -151,6 +152,15 @@ module ActionWebService # :nodoc: body = SOAP::SOAPBody.new(body) SOAP::SOAPEnvelope.new(header, body) end + + def parse_charset(content_type) + return AWSEncoding if content_type.nil? + if /^text\/xml(?:\s*;\s*charset=([^"]+|"[^"]+"))$/i =~ content_type + $1 + else + AWSEncoding + end + end end end end -- cgit v1.2.3