Skip to content

Commit

Permalink
No longer necessary to use cowboy fork.
Browse files Browse the repository at this point in the history
The master branch of cowboy now has all the support for HTTP2 that
is required for gRPC.
  • Loading branch information
willemdj committed Nov 21, 2017
1 parent 16d8fcf commit ede30ff
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ PROJECT_VERSION = 0.1.0
SP = 4

DEPS = cowboy grpc_lib
dep_cowboy = git https://github.com/willemdj/cowboy
# Use the cowboy version that has support for trailers.
dep_cowboy_commit = master
dep_grpc_lib = git https://github.com/Bluehouse-Technology/grpc_lib

TEST_DEPS = grpc_client
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ tested against the go gRPC implementation.

## Dependencies

- [cowboy](https://github.com/willemdj/cowboy) is used for the server.
This is a fork with some additional HTTP/2, most notably support for
trailers.
- [cowboy](https://github.com/ninenines/cowboy) is used for the server.

- [gpb](https://github.com/tomas-abrahamsson/gpb) is used to encode and
decode the protobuf messages. This is a 'build' dependency: gpb is
Expand Down
10 changes: 5 additions & 5 deletions src/grpc_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ get_authfun(_, _) ->
undefined.

authenticate(Req, #{auth_fun := AuthFun}) when is_function(AuthFun) ->
case cowboy_req:peercert(Req) of
{ok, Cert} ->
AuthFun(Cert);
{error, no_peercert} ->
false
case cowboy_req:cert(Req) of
undefined ->
false;
Cert when is_binary(Cert) ->
AuthFun(Cert)
end;
authenticate(_Req, _Options) ->
{true, undefined}.
Expand Down
17 changes: 16 additions & 1 deletion src/grpc_stream_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ data(StreamID, IsFin, Data, State0=#state{bytes_received = Received,
-> {cowboy_stream:commands(), State} when State::#state{}.
info(StreamID, Info, State0=#state{next=Next0}) ->
{Commands0, Next} = cowboy_stream:info(StreamID, Info, Next0),
{Commands0, State0#state{next=Next}}.
Commands = remove_date_and_server(Commands0),
{Commands, State0#state{next=Next}}.

-spec terminate(cowboy_stream:streamid(), cowboy_stream:reason(), #state{}) -> any().
terminate(StreamID, Reason, #state{next=Next}) ->
Expand All @@ -83,3 +84,17 @@ terminate(StreamID, Reason, #state{next=Next}) ->
when Resp::cowboy_stream:resp_command().
early_error(StreamID, Reason, PartialReq, Resp, Opts) ->
cowboy_stream:early_error(StreamID, Reason, PartialReq, Resp, Opts).


%%-----------------------------------------------------------------------------
%% Internal functions
%%-----------------------------------------------------------------------------

%% cowboy adds headers for "date" and "server", these must be removed.
remove_date_and_server(Commands) ->
F = fun({headers, Status, Headers}) ->
{headers, Status, maps:without([<<"date">>, <<"server">>], Headers)};
(Other) ->
Other
end,
[F(C) || C <- Commands].

0 comments on commit ede30ff

Please sign in to comment.