Skip to content

Commit

Permalink
Support explicit use of packet option httph and httph_bin
Browse files Browse the repository at this point in the history
  • Loading branch information
IngelaAndin committed Sep 16, 2011
1 parent 8802241 commit 9978850
Show file tree
Hide file tree
Showing 2 changed files with 306 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/ssl/src/ssl_connection.erl
Expand Up @@ -1778,7 +1778,8 @@ format_reply(binary, _, N, Data) when N > 0 -> % Header mode
format_reply(binary, _, _, Data) ->
Data;
format_reply(list, Packet, _, Data)
when Packet == http; Packet == {http, headers}; Packet == http_bin; Packet == {http_bin, headers} ->
when Packet == http; Packet == {http, headers}; Packet == http_bin; Packet == {http_bin, headers}; Packet == httph;
Packet == httph_bin->
Data;
format_reply(list, _,_, Data) ->
binary_to_list(Data).
Expand Down Expand Up @@ -2090,7 +2091,9 @@ set_socket_opts(Socket, [{packet, Packet}| Opts], SockOpts, Other) when Packet =
Packet == tpkt;
Packet == line;
Packet == http;
Packet == http_bin ->
Packet == httph;
Packet == http_bin;
Packet == httph_bin ->
set_socket_opts(Socket, Opts,
SockOpts#socket_options{packet = Packet}, Other);
set_socket_opts(_, [{packet, _} = Opt| _], SockOpts, _) ->
Expand Down
302 changes: 301 additions & 1 deletion lib/ssl/test/ssl_packet_SUITE.erl
Expand Up @@ -151,6 +151,9 @@ all() ->
packet_cdr_decode, packet_cdr_decode_list,
packet_http_decode, packet_http_decode_list,
packet_http_bin_decode_multi, packet_http_error_passive,
packet_httph_active, packet_httph_bin_active,
packet_httph_active_once, packet_httph_bin_active_once,
packet_httph_passive, packet_httph_bin_passive,
packet_line_decode, packet_line_decode_list,
packet_asn1_decode, packet_asn1_decode_list,
packet_tpkt_decode, packet_tpkt_decode_list,
Expand Down Expand Up @@ -1594,7 +1597,7 @@ client_http_decode(Socket, HttpRequest) ->
%%--------------------------------------------------------------------
packet_http_decode_list(doc) ->
["Test setting the packet option {packet, http}, {mode, list}"
"(Body will be litst too)"];
"(Body will be list too)"];
packet_http_decode_list(suite) ->
[];
packet_http_decode_list(Config) when is_list(Config) ->
Expand Down Expand Up @@ -1804,7 +1807,304 @@ server_http_decode_error(Socket, HttpResponse) ->
assert_packet_opt(Socket, http),
ok = ssl:send(Socket, HttpResponse),
ok.
%%--------------------------------------------------------------------
packet_httph_active(doc) ->
["Test setting the packet option {packet, httph}"];
packet_httph_active(suite) ->
[];
packet_httph_active(Config) when is_list(Config) ->
ClientOpts = ?config(client_opts, Config),
ServerOpts = ?config(server_opts, Config),
{ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config),

Trailer = "Content-Encoding: gzip\r\n"
"\r\n",

Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0},
{from, self()},
{mfa, {?MODULE, server_send_trailer,
[Trailer]}},
{options, [{active, true}, binary |
ServerOpts]}]),

Port = ssl_test_lib:inet_port(Server),
Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port},
{host, Hostname},
{from, self()},
{mfa, {?MODULE, client_http_decode_trailer_active,
[]}},
{options, [{active, true},
{packet, httph},
list |
ClientOpts]}]),

ssl_test_lib:check_result(Server, ok, Client, ok),

ssl_test_lib:close(Server),
ssl_test_lib:close(Client).


server_send_trailer(Socket, Trailer)->
ssl:send(Socket, Trailer),
ok.

client_http_decode_trailer_active(Socket) ->
receive
{ssl, Socket,
{http_header,36,'Content-Encoding',undefined,"gzip"}} ->
ok;
Other1 ->
exit({?LINE, Other1})
end,
receive
{ssl, Socket, http_eoh} ->
ok;
Other2 ->
exit({?LINE, Other2})
end,
ok.

%%--------------------------------------------------------------------
packet_httph_bin_active(doc) ->
["Test setting the packet option {packet, httph_bin}"];
packet_httph_bin_active(suite) ->
[];
packet_httph_bin_active(Config) when is_list(Config) ->
ClientOpts = ?config(client_opts, Config),
ServerOpts = ?config(server_opts, Config),
{ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config),

Trailer = "Content-Encoding: gzip\r\n"
"\r\n",

Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0},
{from, self()},
{mfa, {?MODULE, server_send_trailer,
[Trailer]}},
{options, [{active, true}, binary |
ServerOpts]}]),

Port = ssl_test_lib:inet_port(Server),
Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port},
{host, Hostname},
{from, self()},
{mfa, {?MODULE, client_http_decode_trailer_bin_active,
[]}},
{options, [{active, true},
{packet, httph_bin},
list |
ClientOpts]}]),

ssl_test_lib:check_result(Server, ok, Client, ok),

ssl_test_lib:close(Server),
ssl_test_lib:close(Client).

client_http_decode_trailer_bin_active(Socket) ->
receive
{ssl, Socket,
{http_header,36,'Content-Encoding',undefined, <<"gzip">>}} ->
ok;
Other1 ->
exit({?LINE, Other1})
end,
receive
{ssl, Socket, http_eoh} ->
ok;
Other2 ->
exit({?LINE, Other2})
end,
ok.
%%--------------------------------------------------------------------
packet_httph_active_once(doc) ->
["Test setting the packet option {packet, httph}"];
packet_httph_active_once(suite) ->
[];
packet_httph_active_once(Config) when is_list(Config) ->
ClientOpts = ?config(client_opts, Config),
ServerOpts = ?config(server_opts, Config),
{ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config),

Trailer = "Content-Encoding: gzip\r\n"
"\r\n",

Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0},
{from, self()},
{mfa, {?MODULE, server_send_trailer,
[Trailer]}},
{options, [{active, true}, binary |
ServerOpts]}]),

Port = ssl_test_lib:inet_port(Server),
Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port},
{host, Hostname},
{from, self()},
{mfa, {?MODULE, client_http_decode_trailer_active_once,
[]}},
{options, [{active, false},
{packet, httph},
list |
ClientOpts]}]),

ssl_test_lib:check_result(Server, ok, Client, ok),

ssl_test_lib:close(Server),
ssl_test_lib:close(Client).


client_http_decode_trailer_active_once(Socket) ->
ssl:setopts(Socket, [{active, once}]),
receive
{ssl, Socket,
{http_header,36,'Content-Encoding',undefined,"gzip"}} ->
ok;
Other1 ->
exit({?LINE, Other1})
end,
ssl:setopts(Socket, [{active, once}]),
receive
{ssl, Socket, http_eoh} ->
ok;
Other2 ->
exit({?LINE, Other2})
end,
ok.
%%--------------------------------------------------------------------
packet_httph_bin_active_once(doc) ->
["Test setting the packet option {packet, httph_bin}"];
packet_httph_bin_active_once(suite) ->
[];
packet_httph_bin_active_once(Config) when is_list(Config) ->
ClientOpts = ?config(client_opts, Config),
ServerOpts = ?config(server_opts, Config),
{ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config),

Trailer = "Content-Encoding: gzip\r\n"
"\r\n",

Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0},
{from, self()},
{mfa, {?MODULE, server_send_trailer,
[Trailer]}},
{options, [{active, true}, binary |
ServerOpts]}]),

Port = ssl_test_lib:inet_port(Server),
Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port},
{host, Hostname},
{from, self()},
{mfa, {?MODULE, client_http_decode_trailer_bin_active_once,
[]}},
{options, [{active, false},
{packet, httph_bin},
list |
ClientOpts]}]),

ssl_test_lib:check_result(Server, ok, Client, ok),

ssl_test_lib:close(Server),
ssl_test_lib:close(Client).

client_http_decode_trailer_bin_active_once(Socket) ->
ssl:setopts(Socket, [{active, once}]),
receive
{ssl, Socket,
{http_header,36,'Content-Encoding',undefined, <<"gzip">>}} ->
ok;
Other1 ->
exit({?LINE, Other1})
end,
ssl:setopts(Socket, [{active, once}]),
receive
{ssl, Socket, http_eoh} ->
ok;
Other2 ->
exit({?LINE, Other2})
end,
ok.

%%--------------------------------------------------------------------

packet_httph_passive(doc) ->
["Test setting the packet option {packet, httph}"];
packet_httph_passive(suite) ->
[];
packet_httph_passive(Config) when is_list(Config) ->
ClientOpts = ?config(client_opts, Config),
ServerOpts = ?config(server_opts, Config),
{ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config),

Trailer = "Content-Encoding: gzip\r\n"
"\r\n",

Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0},
{from, self()},
{mfa, {?MODULE, server_send_trailer,
[Trailer]}},
{options, [{active, true}, binary |
ServerOpts]}]),

Port = ssl_test_lib:inet_port(Server),
Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port},
{host, Hostname},
{from, self()},
{mfa, {?MODULE, client_http_decode_trailer_passive,
[]}},
{options, [{active, false},
{packet, httph},
list |
ClientOpts]}]),

ssl_test_lib:check_result(Server, ok, Client, ok),

ssl_test_lib:close(Server),
ssl_test_lib:close(Client).

client_http_decode_trailer_passive(Socket) ->
{ok,{http_header,36,'Content-Encoding',undefined,"gzip"}} = ssl:recv(Socket, 0),
{ok, http_eoh} = ssl:recv(Socket, 0),
ok.

%%--------------------------------------------------------------------
packet_httph_bin_passive(doc) ->
["Test setting the packet option {packet, httph_bin}"];
packet_httph_bin_passive(suite) ->
[];
packet_httph_bin_passive(Config) when is_list(Config) ->
ClientOpts = ?config(client_opts, Config),
ServerOpts = ?config(server_opts, Config),
{ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config),

Trailer = "Content-Encoding: gzip\r\n"
"\r\n",

Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0},
{from, self()},
{mfa, {?MODULE, server_send_trailer,
[Trailer]}},
{options, [{active, true}, binary |
ServerOpts]}]),

Port = ssl_test_lib:inet_port(Server),
Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port},
{host, Hostname},
{from, self()},
{mfa, {?MODULE, client_http_decode_trailer_bin_passive,
[]}},
{options, [{active, false},
{packet, httph_bin},
list |
ClientOpts]}]),

ssl_test_lib:check_result(Server, ok, Client, ok),

ssl_test_lib:close(Server),
ssl_test_lib:close(Client).

client_http_decode_trailer_bin_passive(Socket) ->
{ok,{http_header,36,'Content-Encoding',undefined,<<"gzip">>}} = ssl:recv(Socket, 0),
{ok, http_eoh} = ssl:recv(Socket, 0),
ok.

%%--------------------------------------------------------------------
packet_line_decode(doc) ->
Expand Down

0 comments on commit 9978850

Please sign in to comment.