aboutsummaryrefslogtreecommitdiffstats
path: root/lib/inets
diff options
context:
space:
mode:
authorMicael Karlberg <[email protected]>2011-11-22 12:39:36 +0100
committerMicael Karlberg <[email protected]>2011-11-22 12:39:36 +0100
commit019e0f5483e3df00f27ca9f6bb7a5e02e1705314 (patch)
tree74e84d610e4e022c1c066e451d024e399d108cc2 /lib/inets
parent87abb60af318a471df1c3614bfa860a7fd55ccf7 (diff)
parent3a94ee84c863798aed81869c71d4ab6b4b902ee5 (diff)
downloadotp-019e0f5483e3df00f27ca9f6bb7a5e02e1705314.tar.gz
otp-019e0f5483e3df00f27ca9f6bb7a5e02e1705314.tar.bz2
otp-019e0f5483e3df00f27ca9f6bb7a5e02e1705314.zip
Merge branch 'bmk/inets/httpd/bad_msg_size/OTP-9733' into bmk/inets/inets58_integration2
Diffstat (limited to 'lib/inets')
-rw-r--r--lib/inets/src/http_server/httpd_log.erl126
-rw-r--r--lib/inets/test/httpc_SUITE.erl2
2 files changed, 85 insertions, 43 deletions
diff --git a/lib/inets/src/http_server/httpd_log.erl b/lib/inets/src/http_server/httpd_log.erl
index db1e2c627a..60ab326a20 100644
--- a/lib/inets/src/http_server/httpd_log.erl
+++ b/lib/inets/src/http_server/httpd_log.erl
@@ -24,68 +24,110 @@
-export([access_entry/8, error_entry/5, error_report_entry/5,
security_entry/5]).
+
%%%=========================================================================
%%% Internal Application API
%%%=========================================================================
-access_entry(Log, NoLog, Info, RFC931, AuthUser, Date, StatusCode, Bytes) ->
- ConfigDB = Info#mod.config_db,
- case httpd_util:lookup(ConfigDB, Log) of
- undefined ->
- NoLog;
- LogRef ->
- {_, RemoteHost}
- = (Info#mod.init_data)#init_data.peername,
- RequestLine = Info#mod.request_line,
- Headers = Info#mod.parsed_header,
- Entry = do_access_entry(ConfigDB, Headers, RequestLine,
- RemoteHost, RFC931, AuthUser,
- Date, StatusCode, Bytes),
- {LogRef, Entry}
- end.
-error_entry(Log, NoLog, Info, Date, Reason) ->
- ConfigDB = Info#mod.config_db,
- case httpd_util:lookup(ConfigDB, Log) of
- undefined ->
- NoLog;
- LogRef ->
- {_, RemoteHost} =
- (Info#mod.init_data)#init_data.peername,
- URI = Info#mod.request_uri,
- Entry = do_error_entry(ConfigDB, RemoteHost, URI, Date, Reason),
- {LogRef, Entry}
- end.
+-spec access_entry(Log :: term(), % Id of the log
+ NoLog :: term(), % What to return when no log is found
+ Info :: #mod{},
+ RFC931 :: string(),
+ AuthUser :: string(),
+ Date :: string(),
+ StatusCode :: pos_integer(),
+ Size :: pos_integer() | string()) ->
+ {Log :: atom() | pid(), Entry :: string()}.
+
+access_entry(Log, NoLog, Info, RFC931, AuthUser, Date, StatusCode, SizeStr)
+ when is_list(SizeStr) ->
+ Size =
+ case (catch list_to_integer(SizeStr)) of
+ I when is_integer(I) ->
+ I;
+ _ ->
+ SizeStr % This is better then nothing
+ end,
+ access_entry(Log, NoLog, Info, RFC931, AuthUser, Date, StatusCode, Size);
+access_entry(Log, NoLog,
+ #mod{config_db = ConfigDB,
+ init_data = #init_data{peername = {_, RemoteHost}},
+ request_line = RequestLine,
+ parsed_header = Headers},
+ RFC931, AuthUser, Date, StatusCode, Size) ->
+ MakeEntry =
+ fun() ->
+ do_access_entry(ConfigDB, Headers, RequestLine,
+ RemoteHost, RFC931, AuthUser,
+ Date, StatusCode, Size)
+ end,
+ log_entry(Log, NoLog, ConfigDB, MakeEntry).
+
+
+-spec error_entry(Log :: term(), % Id of the log
+ NoLog :: term(), % What to return when no log is found
+ Info :: #mod{},
+ Date :: string(),
+ Reason :: term()) ->
+ {Log :: atom() | pid(), Entry :: string()}.
+
+error_entry(Log, NoLog,
+ #mod{config_db = ConfigDB,
+ init_data = #init_data{peername = {_, RemoteHost}},
+ request_uri = URI}, Date, Reason) ->
+ MakeEntry =
+ fun() ->
+ do_error_entry(ConfigDB, RemoteHost, URI, Date, Reason)
+ end,
+ log_entry(Log, NoLog, ConfigDB, MakeEntry).
+
+
+-spec error_report_entry(Log :: term(),
+ NoLog :: term(),
+ ConfigDB :: term(),
+ Date :: string(),
+ ErrroStr :: string()) ->
+ {Log :: atom() | pid(), Entry :: string()}.
error_report_entry(Log, NoLog, ConfigDb, Date, ErrorStr) ->
- case httpd_util:lookup(ConfigDb, Log) of
- undefined ->
- NoLog;
- LogRef ->
- Entry = io_lib:format("[~s], ~s~n", [Date, ErrorStr]),
- {LogRef, Entry}
- end.
+ MakeEntry = fun() -> io_lib:format("[~s], ~s~n", [Date, ErrorStr]) end,
+ log_entry(Log, NoLog, ConfigDb, MakeEntry).
+
-security_entry(Log, NoLog, #mod{config_db = ConfigDb}, Date, Reason) ->
+-spec security_entry(Log :: term(),
+ NoLog :: term(),
+ ConfigDB :: term(),
+ Date :: string(),
+ Reason :: term()) ->
+ {Log :: atom() | pid(), Entry :: string()}.
+
+security_entry(Log, NoLog, #mod{config_db = ConfigDB}, Date, Reason) ->
+ MakeEntry = fun() -> io_lib:format("[~s] ~s~n", [Date, Reason]) end,
+ log_entry(Log, NoLog, ConfigDB, MakeEntry).
+
+
+log_entry(Log, NoLog, ConfigDb, MakeEntry) when is_function(MakeEntry) ->
case httpd_util:lookup(ConfigDb, Log) of
undefined ->
NoLog;
LogRef ->
- Entry = io_lib:format("[~s] ~s~n", [Date, Reason]),
- {LogRef, Entry}
+ {LogRef, MakeEntry()}
end.
-
+
+
%%%========================================================================
%%% Internal functions
%%%========================================================================
+
do_access_entry(ConfigDB, Headers, RequestLine,
- RemoteHost, RFC931, AuthUser, Date, StatusCode,
- Bytes) ->
+ RemoteHost, RFC931, AuthUser, Date, StatusCode,
+ Size) ->
case httpd_util:lookup(ConfigDB, log_format, common) of
common ->
lists:flatten(io_lib:format("~s ~s ~s [~s] \"~s\" ~w ~w~n",
[RemoteHost, RFC931, AuthUser, Date,
RequestLine,
- StatusCode, Bytes]));
+ StatusCode, Size]));
combined ->
Referer =
proplists:get_value("referer", Headers, "-"),
@@ -94,7 +136,7 @@ do_access_entry(ConfigDB, Headers, RequestLine,
Headers, "-"),
io_lib:format("~s ~s ~s [~s] \"~s\" ~w ~w ~s ~s~n",
[RemoteHost, RFC931, AuthUser, Date,
- RequestLine, StatusCode, Bytes,
+ RequestLine, StatusCode, Size,
Referer, UserAgent])
end.
diff --git a/lib/inets/test/httpc_SUITE.erl b/lib/inets/test/httpc_SUITE.erl
index d86e52f3d5..2b580cd95d 100644
--- a/lib/inets/test/httpc_SUITE.erl
+++ b/lib/inets/test/httpc_SUITE.erl
@@ -370,7 +370,7 @@ init_per_testcase(Case, Timeout, Config) ->
%% This will fail for the ipv6_ - cases (but that is ok)
ProxyExceptions = ["localhost", ?IPV6_LOCAL_HOST],
- http:set_options([{proxy, {{?PROXY, ?PROXY_PORT}, ProxyExceptions}}]),
+ httpc:set_options([{proxy, {{?PROXY, ?PROXY_PORT}, ProxyExceptions}}]),
inets:enable_trace(max, io, httpc),
%% inets:enable_trace(max, io, all),
%% snmp:set_trace([gen_tcp]),