简体   繁体   中英

How to put file content to http request header by using Apache httpd

I can send http request to /foo, add header plaa to request and finally redirect request to /bar with following Apache httpd configuration (foobar.conf file)...

<LocationMatch "/foo">

ProxyPass http://localhost/bar
ProxyPassReverse http://localhost/bar
ProxyPassReverse https://localhost/bar

RequestHeader set plaa "hello"

</LocationMatch>

How can I put plaa header's value as base64 encoded file content?

I could image I could do it like this...

sed -i s_plaa_$(cat file.txt | base64)_g foobar.conf

but I'm wondering is there any built in way to do it with Apache.

Apache httpd do not support reading http header content from file.

Here's quick fix for doing this manually in Unix environment.

(Following steps could be easily put to script file if you want to.)

Step 1.

    Go to 'location_where_apache_httpd_is_running:/etc/httpd/conf.d'

Step 2. Create file for header value.

    echo 'your base are belong to us' > header_value.txt

Step 3. Write following lines to file apache_app.conf_base.

    Listen 8001
    ProxyPass /foobar/ http://localhost:8002/foobar
    ProxyPassReverse /foobar/ http://localhost:8002/foobar
    Header add App-Header "value"
    RequestHeader App-Header "value"

Step 4. Replace 'value' strings with base64 encoded header_value.txt.

    sed s_value_$(echo $(cat message.json | tr -d "\n\r") | base64 -w 0)_g apache_app.conf_base > apache_app.conf

Step 5. Restart httpd

    service httpd restart

Now apache httpd do following things based on apache_app.conf.

  1. Redirect requests from localhost:8001/foobar to localhost:8002/foobar
  2. Attach header 'App-Header' with value as base64 encoded lines from file header_value.txt.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM