Guest User

Untitled

a guest
Feb 20th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. def xml_http_request( url, props, headers = nil)
  2. # xhr doesn't seem to work because it's setting text/html before */xml in Accept header
  3. # also, it uses IndifferentAccess.merge which overrides any Accept header I try to send in!
  4. #xml_http_request '/omis/emails', props, 'Accept' => 'application/xml, text/xml'
  5. post url, props,
  6. (headers || {}).merge( 'X-Requested-With' => 'XMLHttpRequest',
  7. 'Accept' => 'application/xml, text/xml')
  8.  
  9. if( @http_basic_authentication_credentials_sent)
  10. if( @http_basic_authentication_credentials_are_correct)
  11. assert_response :success
  12. else
  13. assert_response 401
  14. end
  15. # TODO: validate return structure
  16. else
  17. assert_response 401 # HTTP basic authentication challenge
  18. assert_equal "Basic realm=\"user.joyomi.com\"", response.headers["WWW-Authenticate"]
  19. @http_basic_authentication_credentials_sent = true
  20. # repeat request with Authorization header
  21. xml_http_request( url, props, 'Authorization' => 'Basic ' + Base64.encode64(@username + ':' + @password)) #recurse
  22. end
  23. end
Add Comment
Please, Sign In to add comment