README.md in unleash-4.2.1 vs README.md in unleash-4.3.0
- old
+ new
@@ -39,30 +39,46 @@
It is **required** to configure:
- `url` of the unleash server
- `app_name` with the name of the runninng application.
- `custom_http_headers` with `{'Authorization': '<API token>'}` when using Unleash v4.0.0 and later.
-Please substitute the example `'http://unleash.herokuapp.com/api'` for the url of your own instance.
+Please substitute the example `'https://unleash.herokuapp.com/api'` for the url of your own instance.
It is **highly recommended** to configure:
- `instance_id` parameter with a unique identifier for the running instance.
```ruby
Unleash.configure do |config|
config.app_name = 'my_ruby_app'
- config.url = 'http://unleash.herokuapp.com/api'
+ config.url = 'https://unleash.herokuapp.com/api'
config.custom_http_headers = {'Authorization': '<API token>'}
end
```
or instantiate the client with the valid configuration:
```ruby
-UNLEASH = Unleash::Client.new(url: 'http://unleash.herokuapp.com/api', app_name: 'my_ruby_app', custom_http_headers: {'Authorization': '<API token>'})
+UNLEASH = Unleash::Client.new(url: 'https://unleash.herokuapp.com/api', app_name: 'my_ruby_app', custom_http_headers: {'Authorization': '<API token>'})
```
+## Dynamic custom HTTP headers
+If you need custom HTTP headers that change during the lifetime of the client, the `custom_http_headers` can be given as a `Proc`.
+
+```ruby
+Unleash.configure do |config|
+ config.app_name = 'my_ruby_app'
+ config.url = 'https://unleash.herokuapp.com/api'
+ config.custom_http_headers = proc do
+ {
+ 'Authorization': '<API token>',
+ 'X-Client-Request-Time': Time.now.iso8601
+ }
+ end
+end
+```
+
#### List of Arguments
Argument | Description | Required? | Type | Default Value|
---------|-------------|-----------|-------|---------------|
`url` | Unleash server URL. | Y | String | N/A |
@@ -72,11 +88,11 @@
`project_name` | Name of the project to retrieve features from. If not set, all feature flags will be retrieved. | N | String | nil |
`refresh_interval` | How often the unleash client should check with the server for configuration changes. | N | Integer | 15 |
`metrics_interval` | How often the unleash client should send metrics to server. | N | Integer | 60 |
`disable_client` | Disables all communication with the Unleash server, effectively taking it *offline*. If set, `is_enabled?` will always answer with the `default_value` and configuration validation is skipped. Defeats the entire purpose of using unleash, but can be useful in when running tests. | N | Boolean | `false` |
`disable_metrics` | Disables sending metrics to Unleash server. | N | Boolean | `false` |
-`custom_http_headers` | Custom headers to send to Unleash. As of Unleash v4.0.0, the `Authorization` header is required. For example: `{'Authorization': '<API token>'}` | N | Hash | {} |
+`custom_http_headers` | Custom headers to send to Unleash. As of Unleash v4.0.0, the `Authorization` header is required. For example: `{'Authorization': '<API token>'}` | N | Hash/Proc | {} |
`timeout` | How long to wait for the connection to be established or wait in reading state (open_timeout/read_timeout) | N | Integer | 30 |
`retry_limit` | How many consecutive failures in connecting to the Unleash server are allowed before giving up. The default is to retry indefinitely. | N | Float::INFINITY | 5 |
`backup_file` | Filename to store the last known state from the Unleash server. Best to not change this from the default. | N | String | `Dir.tmpdir + "/unleash-#{app_name}-repo.json` |
`logger` | Specify a custom `Logger` class to handle logs for the Unleash client. | N | Class | `Logger.new(STDOUT)` |
`log_level` | Change the log level for the `Logger` class. Constant from `Logger::Severity`. | N | Constant | `Logger::WARN` |
@@ -93,11 +109,11 @@
```ruby
require 'unleash'
require 'unleash/context'
-@unleash = Unleash::Client.new(app_name: 'my_ruby_app', url: 'http://unleash.herokuapp.com/api', custom_http_headers: { 'Authorization': '<API token>' })
+@unleash = Unleash::Client.new(app_name: 'my_ruby_app', url: 'https://unleash.herokuapp.com/api', custom_http_headers: { 'Authorization': '<API token>' })
feature_name = "AwesomeFeature"
unleash_context = Unleash::Context.new
unleash_context.user_id = 123
@@ -115,11 +131,11 @@
Put in `config/initializers/unleash.rb`:
```ruby
Unleash.configure do |config|
config.app_name = Rails.application.class.parent.to_s
- config.url = 'http://unleash.herokuapp.com/api'
+ config.url = 'https://unleash.herokuapp.com/api'
# config.instance_id = "#{Socket.gethostname}"
config.logger = Rails.logger
config.environment = Rails.env
end
@@ -154,11 +170,11 @@
Then you may keep the client configuration still in `config/initializers/unleash.rb`:
```ruby
Unleash.configure do |config|
config.app_name = Rails.application.class.parent.to_s
config.environment = Rails.env
- config.url = 'http://unleash.herokuapp.com/api'
+ config.url = 'https://unleash.herokuapp.com/api'
config.custom_http_headers = {'Authorization': '<API token>'}
end
```
But you must ensure that the unleash client is instantiated only after the process is forked.
@@ -202,11 +218,11 @@
# ...
::UNLEASH = Unleash::Client.new(
app_name: 'my_rails_app',
environment: 'development',
- url: 'http://unleash.herokuapp.com/api',
+ url: 'https://unleash.herokuapp.com/api',
custom_http_headers: {'Authorization': '<API token>'},
)
end
on_worker_shutdown do
@@ -228,11 +244,11 @@
Unleash.configure do |config|
config.app_name = Rails.application.class.parent.to_s
# config.instance_id = "#{Socket.gethostname}"
config.logger = Rails.logger
config.environment = Rails.env
- config.url = 'http://unleash.herokuapp.com/api'
+ config.url = 'https://unleash.herokuapp.com/api'
config.custom_http_headers = {'Authorization': '<API token>'}
end
UNLEASH = Unleash::Client.new
end
@@ -363,15 +379,15 @@
Bootstrap configuration allows the client to be initialized with a predefined set of toggle states.
Bootstrapping can be configured by providing a bootstrap configuration when initializing the client.
```ruby
@unleash = Unleash::Client.new(
- url: 'http://unleash.herokuapp.com/api',
+ url: 'https://unleash.herokuapp.com/api',
app_name: 'my_ruby_app',
custom_http_headers: { 'Authorization': '<API token>' },
bootstrap_config: Unleash::Bootstrap::Configuration.new({
- url: "http://unleash.herokuapp.com/api/client/features",
+ url: "https://unleash.herokuapp.com/api/client/features",
url_headers: {'Authorization': '<API token>'}
})
)
```
The `Bootstrap::Configuration` initializer takes a hash with one of the following options specified:
@@ -393,11 +409,11 @@
Example usage:
First saving the toggles locally:
```shell
-curl -H 'Authorization: <API token>' -XGET 'http://unleash.herokuapp.com/api' > ./default-toggles.json
+curl -H 'Authorization: <API token>' -XGET 'https://unleash.herokuapp.com/api' > ./default-toggles.json
```
Now using them on start up:
```ruby
@@ -406,10 +422,10 @@
File.read('./default-toggles.json')
}
@unleash = Unleash::Client.new(
app_name: 'my_ruby_app',
- url: 'http://unleash.herokuapp.com/api',
+ url: 'https://unleash.herokuapp.com/api',
custom_http_headers: { 'Authorization': '<API token>' },
bootstrap_config: Unleash::Bootstrap::Configuration.new({
block: custom_boostrapper
})
)