THRIFT-306. erlang: Let thrift_http_transport specify custom HTTP headers
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@760165 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/erl/src/thrift_http_transport.erl b/lib/erl/src/thrift_http_transport.erl
index 05a0311..44daf50 100644
--- a/lib/erl/src/thrift_http_transport.erl
+++ b/lib/erl/src/thrift_http_transport.erl
@@ -28,7 +28,8 @@
path, % string()
read_buffer, % iolist()
write_buffer, % iolist()
- http_options % see http(3)
+ http_options, % see http(3)
+ extra_headers % [{str(), str()}, ...]
}).
%%====================================================================
@@ -99,11 +100,14 @@
path = Path,
read_buffer = [],
write_buffer = [],
- http_options = []},
+ http_options = [],
+ extra_headers = []},
ApplyOption =
fun
({http_options, HttpOpts}, State = #http_transport{}) ->
State#http_transport{http_options = HttpOpts};
+ ({extra_headers, ExtraHeaders}, State = #http_transport{}) ->
+ State#http_transport{extra_headers = ExtraHeaders};
(Other, #http_transport{}) ->
{invalid_option, Other};
(_, Error) ->
@@ -158,7 +162,8 @@
path = Path,
read_buffer = Rbuf,
write_buffer = Wbuf,
- http_options = HttpOptions}) ->
+ http_options = HttpOptions,
+ extra_headers = ExtraHeaders}) ->
case iolist_to_binary(Wbuf) of
<<>> ->
%% Don't bother flushing empty buffers.
@@ -167,7 +172,7 @@
{ok, {{_Version, 200, _ReasonPhrase}, _Headers, Body}} =
http:request(post,
{"http://" ++ Host ++ Path,
- [{"User-Agent", "Erlang/thrift_http_transport"}],
+ [{"User-Agent", "Erlang/thrift_http_transport"} | ExtraHeaders],
"application/x-thrift",
WBinary},
HttpOptions,