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

Pass header to upstream #565

Closed
yaslama opened this issue Oct 20, 2015 · 4 comments
Closed

Pass header to upstream #565

yaslama opened this issue Oct 20, 2015 · 4 comments

Comments

@yaslama
Copy link

yaslama commented Oct 20, 2015

Hi,
I didn't find how to pass header to upstream like proxy_set_header in nginx (or fastcgi_param). Did I miss something ?

@kazuho
Copy link
Member

kazuho commented Oct 22, 2015

There is no such setting, and I believe there is generally no need to so such thing.

You can modify the value sent by host header using proxy.preserve-host, disable persistent connections using proxy.timeout.keepalive.

Or do you want to modify other headers? If so, can you name them and explain why?

@kazuho kazuho added the proxy label Oct 22, 2015
@yaslama
Copy link
Author

yaslama commented Oct 22, 2015

Thanks for your answer. In fact my use case is a multi-site php installation using hhvm running in proxygen mode (the integrated web server). There is a mapping between hostnames and directories: host1->dir1, host2->dir2, etc..
I prefer to have a single place where this mapping is stored and it needs to be in the h2o config because h2o is serving the static files.
When using nginx, I use for instance the following configuration snippet:

server {
  listen <ip>:443 ssl http2;
  server_name <host1>;
  root <dir1>;
  set $site_directory <dir1>;
  location / {
    try_files $uri @rewrite;
  }
  location @rewrite {
    rewrite ^ /index.php;
  }
  location ~ \.php$ {
   proxy_set_header Site-Directory $site_directory;
   proxy_pass http://localhost:8000/;
  }
}

And in my main index.php, I use the header "Site-Directory" to know what is the root dir of the current site, and I don't need to store in another place the map between host_i and dir_i.
I hope my explanation is clear enough.
Thanks a lot!

@kazuho
Copy link
Member

kazuho commented Oct 23, 2015

@yaslama Thank you for the clarification. Understood.

Will consider how I should provide a way to tweak the request headers sent to backend.

@kazuho
Copy link
Member

kazuho commented Jan 4, 2016

As covered in the test implemented in #666, it is now possible to use mruby handler's http_request method to issue an HTTP request with arbitrary headers to upstream, and send the response downstream.

https://github.com/h2o/h2o/blob/94a4aa2/t/50mruby-http-request.t#L47-L60 would be a good place to look at how it can be done.

Please note that the API is subject to change until we release 1.7.0. Also, the documentation will be available at time of the release.

@kazuho kazuho closed this as completed Jan 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants