Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base URL "doubling" when using Cossack::Client #2

Closed
aisrael opened this issue Feb 5, 2018 · 2 comments
Closed

Base URL "doubling" when using Cossack::Client #2

aisrael opened this issue Feb 5, 2018 · 2 comments

Comments

@aisrael
Copy link
Contributor

aisrael commented Feb 5, 2018

Issue Summary

Am trying to use Hi8 to automatically record and playback HTTP interactions for a Web service client, but am using Cossack rather than just HTTP::Client.

The first time the spec is executed, it passes and HI8 records the interaction as expected. However, subsequent test runs fail with Real HTTP connections are disabled. Unregistered request: ....

Further investigation reveals that the recorded uri in the cassette has the base URL "doubled". E.g., "https://api.fixer.io/latest" becomes "https://api.fixer.iohttps://api.fixer.io/latest".

The same behaviour was not observed using whether using HTTP::Client.get() or HTTP::Client.new().

Sample code

    HI8.use_cassette("using_cossack_client") do
      client = Cossack::Client.new("https://api.fixer.io")
      resp = client.get("/latest?base=USD")
      resp.status.should eq(200)
    end

The full gist can be found at here

Expected behaviour

Spec should pass.

Actual behaviour

Real HTTP connections are disabled. Unregistered request: GET https://api.fixer.iohttps://api.fixer.io/latest?base=USD with headers {"User-Agent" => "Cossack v0.1.4", "Host" => "api.fixer.io"}

Environment

  • Hi8 commit: 1e9981a
  • Crystal 0.24.1
  • Cossack 0.1.4
  • macOS 10.13.3
@aisrael
Copy link
Contributor Author

aisrael commented Feb 5, 2018

So I've traced through this and I seem to have isolated where the problem occurs.

In HI8::HTTPHelpers#uri_creator (episode.cr:15) it concatenates host + resources.

For some reason, when using Cossack the @request.resource.to_s (episode.cr:47) also embeds the host. Hence, the "doubling" when the interaction is recorded.

Not sure if this is a Cossack issue or whether it should be treated as a special case by HI8.

@vonKingsley
Copy link
Owner

Your fix works for me. I'll close this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants