Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def xml_http_request( url, props, headers = nil)
- # xhr doesn't seem to work because it's setting text/html before */xml in Accept header
- # also, it uses IndifferentAccess.merge which overrides any Accept header I try to send in!
- #xml_http_request '/omis/emails', props, 'Accept' => 'application/xml, text/xml'
- post url, props,
- (headers || {}).merge( 'X-Requested-With' => 'XMLHttpRequest',
- 'Accept' => 'application/xml, text/xml')
- if( @http_basic_authentication_credentials_sent)
- if( @http_basic_authentication_credentials_are_correct)
- assert_response :success
- else
- assert_response 401
- end
- # TODO: validate return structure
- else
- assert_response 401 # HTTP basic authentication challenge
- assert_equal "Basic realm=\"user.joyomi.com\"", response.headers["WWW-Authenticate"]
- @http_basic_authentication_credentials_sent = true
- # repeat request with Authorization header
- xml_http_request( url, props, 'Authorization' => 'Basic ' + Base64.encode64(@username + ':' + @password)) #recurse
- end
- end
Add Comment
Please, Sign In to add comment