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

400 Bad Request: malformed Host header #448

Closed
jaydipdave opened this issue Sep 16, 2016 · 16 comments
Closed

400 Bad Request: malformed Host header #448

jaydipdave opened this issue Sep 16, 2016 · 16 comments

Comments

@jaydipdave
Copy link

jaydipdave commented Sep 16, 2016

It is required to have "Host:" header in docker_api, even when you request though "unix:///var/run/docker.sock", when you use HTTP/1.1.

issue:

================================================================================ Error executing actioncreate` on resource 'docker_network[mesos_network]'
================================================================================

Docker::Error::ClientError
--------------------------
400 Bad Request: malformed Host header

Cookbook Trace:
---------------
/var/cache/chef/cookbooks/docker/libraries/docker_network.rb:26:in `block (2 levels) in <class:DockerNetwork>'
/var/cache/chef/cookbooks/docker/libraries/helpers_base.rb:66:in `with_retries'
/var/cache/chef/cookbooks/docker/libraries/docker_network.rb:26:in `block in <class:DockerNetwork>'
/var/cache/chef/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/action_class.rb:72:in `load_current_resource'
/var/cache/chef/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:78:in `run_action'
/var/cache/chef/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:106:in `block (2 levels) in converge'
/var/cache/chef/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:106:in `each'
/var/cache/chef/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:106:in `block in converge'
/var/cache/chef/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:105:in `converge'

Resource Declaration:
---------------------
# In /var/cache/chef/cookbooks/env_mesos/recipes/_set_docker.rb`

I added a dummy "Host" header in : docker-api-1.31.0/lib/docker/connection.rb


  # compiles a request.
  def compile_request_params(http_method, path, query = nil, opts = nil, &block)
    query ||= {}
    opts ||= {}
    headers = opts.delete(:headers) || {}
    content_type = opts[:body].nil? ?  'text/plain' : 'application/json'
    user_agent = "Swipely/Docker-API #{Docker::VERSION}"
    {
      :method        => http_method,
      :path          => "/v#{Docker::API_VERSION}#{path}",
      :query         => query,
      :headers       => { 'Content-Type' => content_type,
                          'Host'   => "localhost",
                          'User-Agent'   => user_agent,
                        }.merge(headers),
      :expects       => (200..204).to_a << 304,
      :idempotent    => http_method == :get,
      :request_block => block
    }.merge(opts).reject { |_, v| v.nil? }
  end
end

And it worked!!!! Thanks.

@tlunter
Copy link
Contributor

tlunter commented Sep 17, 2016

This is in the readme. Update excon.

@et304383
Copy link

et304383 commented Jan 31, 2017

@tlunter I'm lost as to how this is fixed. I'm getting this using the Chef Docker cookbook which relies on this gem to perform a docker registry login. I've linked to this item from that issue. Can you please elaborate what you mean by "This is in the readme" and "Update excon"?

@tlunter
Copy link
Contributor

tlunter commented Jan 31, 2017

Are you positive this is not your issue from the readme in the Known Issues section?

  • If the docker daemon is always responding to your requests with a 400 Bad Request when using UNIX sockets, verify you're running Excon version 0.46.0 or greater. Link

@et304383
Copy link

et304383 commented Jan 31, 2017

Running the latest version of this gem. Is it not installing excon as a dependency?

Edit: the gem for docker-api is getting installed via the Chef gem call which might not be installing dependencies. I'm looking into this as a potential issue with the cookbook.

@et304383
Copy link

That's may be it. The docker api version getting installed is actuall docker-api-1.22.4 and thus excon is excon-0.45.4.

@tlunter
Copy link
Contributor

tlunter commented Jan 31, 2017

This problem is because of a change in the docker engine. Excon is a dependency of docker-api. We do not force you to upgrade excon because docker engine doesn't consider whether or not they break things in their API. This has been noted in the README because it affected multiple people. Did upgrading excon not fix your problem?

@tlunter
Copy link
Contributor

tlunter commented Jan 31, 2017

docker-api v1.22.4 has this for its excon requirement: https://github.com/swipely/docker-api/blob/5dee4c3cadce8ff52922515749aa37e742936470/docker-api.gemspec#L17 . You should be able to update excon just fine.

@et304383
Copy link

Unfortunately I don't have control over this. The gems are installed embedded as part of the Chef execution and not globally. The docker cookbook may need to be modified to support this.

@tlunter
Copy link
Contributor

tlunter commented Jan 31, 2017

I have no idea how chef cookbooks work, so I can't really help there. If you don't have access to a Gemfile somewhere, then you'll need to find another way to specify that your chef setup use excon 0.46+

@jaydipdave
Copy link
Author

@eric-tucker Probably, you are not logged in to the repository, when you are not logged in (have no permissions) you get this error.

If you are using private repository try logging in.

@et304383
Copy link

@jaydipdave this is on the Chef call to docker_registry which performs the login. :)

@jaydipdave
Copy link
Author

Oops. If you are getting the error at the time of login, then it is some other issue. But if you are getting this error after login, may be you want to check the session stuff?!!

You might want to consider opening a ticket here: https://github.com/chef-cookbooks/docker?

@et304383
Copy link

Already done. Link is above where I've referenced this item on the ticket on the Chef Docker cookbook.

@jaydipdave
Copy link
Author

Cool.

@et304383
Copy link

Well once I got issues around the excon version:

Connection reset by peer (Errno::ECONNRESET)

This is a tricky one.

@tlunter
Copy link
Contributor

tlunter commented Jan 31, 2017

If you add EXCON_DEBUG=true as an environment variable, it'll print out all request information.

drnic added a commit to cloudfoundry-community/cf-containers-broker that referenced this issue Apr 9, 2017
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

3 participants