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

Missing hash key: HTTP::Headers::Key(@name="Host") calling client.exec with HTTP::Request #5

Open
vonKingsley opened this issue Feb 6, 2016 · 0 comments

Comments

@vonKingsley
Copy link
Contributor

I use the convenience of HTTP::Client.new and client.exec with a HTTP::Request to put the host:port in the http header. I can easily work around the issue by manually adding the header, but others may come across the issue and be surprised.

WebMock.stub(:post, "www.noroute.com")

url = "www.noroute.com"
headers = HTTP::Headers{"Content-Type" => "application/xml"}
service_call = HTTP::Request.new("POST", "/webservice", headers, "", "HTTP/1.0")
client = HTTP::Client.new(url, ssl: true)
web_response = client.exec service_call

Mocking with above code throws the below error

Missing hash key: HTTP::Headers::Key(@name="Host") (KeyError)
[4515630242] *CallStack::unwind:Array(Pointer(Void)) +82
[4515630145] *CallStack#initialize<CallStack>:Array(Pointer(Void)) +17
[4515630104] *CallStack::new:CallStack +40
[4515725905] *KeyError@Exception#initialize<KeyError, String, Nil>:CallStack +33
[4515725836] *KeyError::new<String>:KeyError +92
[4515839028] *Hash(HTTP::Headers::Key, Array(String))@Hash(K, V)#fetch<Hash(HTTP::Headers::Key, Array(String)), HTTP::Headers::Key>:Array(String) +148
[4515836420] *HTTP::Headers#fetch<HTTP::Headers, HTTP::Headers::Key>:String +84
[4515836317] *HTTP::Headers#[]<HTTP::Headers, String>:String +61
[4515812979] *WebMock::Stub#matches_host?<WebMock::Stub, HTTP::Request>:Bool +67
[4515812716] *WebMock::Stub#matches?<WebMock::Stub, HTTP::Request>:Bool +140
[4515811239] *WebMock::StubRegistry#find_stub<WebMock::StubRegistry, HTTP::Request>:WebMock::Stub? +103
[4515812143] *WebMock@WebMock::find_stub<HTTP::Request>:WebMock::Stub? +31
[4515844700] *HTTP::Client#exec_internal<HTTP::Client, HTTP::Request>:HTTP::Client::Response +28
[4515844642] *HTTP::Client#exec<HTTP::Client, HTTP::Request>:HTTP::Client::Response +34
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

Successfully merging a pull request may close this issue.

1 participant