Skip to content

Commit

Permalink
merge and remove unclear custom headers feature
Browse files Browse the repository at this point in the history
  • Loading branch information
werbitzky committed Feb 28, 2017
1 parent d530309 commit 03daf52
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
12 changes: 6 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
## 0.3.0

### Improvements:

### Improvements
- add support for mappings
- add support for bulk requests
- bump up library versions (credo, httpoison, mix_test_watch)

## 0.2.0

### Improvements:

- add support for index_new (@manukall)
- add support for poison options (@manukall)
- add support for index refresh (@manukall)
- add shield support (@vdaniuk)
- add support for index_new
- add support for poison options
- add support for index refresh
- add shield support

## 0.1.1

Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ Elastix.Bulk.post elastic_url, lines
Currently we can
* pass options to the JSON decoder used by Elastix ([poison](https://github.com/devinus/poison))
* optionally use shield for authentication ([shield](https://www.elastic.co/products/shield))
* optionally pass along custom headers for every request made to the elasticsearch server(s)s

by setting the respective keys in your `config/config.exs`

Expand All @@ -143,6 +144,11 @@ The above for example will
* lead to the HTTPoison responses being parsed into maps with atom keys instead of string keys (be careful as most of the time this is not a good idea as stated here: https://github.com/devinus/poison#parser).
* use shield for authentication

```elixir
config :elastix,
custom_headers: []
```

## License

Copyright © 2015 El Werbitzky <werbitzky@gmail.com>
Expand Down
17 changes: 11 additions & 6 deletions lib/elastix/http.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,24 @@ defmodule Elastix.HTTP do
headers = headers
|> Keyword.put_new(:"Content-Type", "application/json; charset=UTF-8")

# https://www.elastic.co/guide/en/shield/current/_using_elasticsearch_http_rest_clients_with_shield.html
username = Elastix.config(:username)
password = Elastix.config(:password)
headers = cond do
# https://www.elastic.co/guide/en/shield/current/_using_elasticsearch_http_rest_clients_with_shield.html
Elastix.config(:shield) ->
Keyword.put(headers, :"Authorization", "Basic " <> Base.encode64("#{username}:#{password}"))
Elastix.config(:custom_headers) ->
Elastix.config(:custom_headers).call(%{method: method, url: url,body: body, headers: headers, options: options})
true ->
headers
end

HTTPoison.Base.request(__MODULE__, method, url, body, headers, options, &process_status_code/1, &process_headers/1, &process_response_body/1)
HTTPoison.Base.request(
__MODULE__,
method,
url,
body,
headers,
options,
&process_status_code/1,
&process_headers/1,
&process_response_body/1)
end


Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Elastix.Mixfile do
use Mix.Project

@version "0.4.0"
@version "0.3.0"

def project do
[app: :elastix,
Expand Down

0 comments on commit 03daf52

Please sign in to comment.