Skip to content

Commit

Permalink
New option: request_clientip
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosHe committed Dec 24, 2020
1 parent 57c24c4 commit 8a0793e
Show file tree
Hide file tree
Showing 7 changed files with 239 additions and 33 deletions.
2 changes: 1 addition & 1 deletion HorseLogger.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<DCC_Namespace>System;Xml;Data;Datasnap;Web;Soap;$(DCC_Namespace)</DCC_Namespace>
<DCC_CBuilderOutput>All</DCC_CBuilderOutput>
<SanitizedProjectName>HorseLogger</SanitizedProjectName>
<DCC_UnitSearchPath>$(DCC_UnitSearchPath);modules\.dcp;modules\.dcu;modules;modules\horse\src</DCC_UnitSearchPath>
<DCC_UnitSearchPath>$(DCC_UnitSearchPath);modules\.dcp;modules\.dcu;modules;modules\horse\src;modules\horse-utils-clientip\src</DCC_UnitSearchPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Base_Android)'!=''">
<DCC_CBuilderOutput>None</DCC_CBuilderOutput>
Expand Down
12 changes: 10 additions & 2 deletions boss-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@
"hash": "d41d8cd98f00b204e9800998ecf8427e",
"updated": "2020-06-03T10:22:23.5303461-03:00",
"installedModules": {
"github.com/dliocode/horse-utils-clientip": {
"name": "horse-utils-clientip",
"version": "0.0.5",
"hash": "e70e774b0e0e7248d1e9028fc9c4542e",
"artifacts": {},
"failed": false,
"changed": false
},
"github.com/hashload/horse": {
"name": "horse",
"version": "v2.0.1",
"hash": "a9e80dbc40536b989ad1089a85bb1c5b",
"version": "v2.0.6",
"hash": "cca1769dfab681cfd26ae8499f9045e1",
"artifacts": {},
"failed": false,
"changed": false
Expand Down
7 changes: 4 additions & 3 deletions boss.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"name": "horse-logger",
"description": "Middleware for access logging in HORSE",
"version": "1.0.0",
"homepage": "",
"mainsrc": "src/",
"homepage": "https://github.com/HashLoad/horse-logger",
"mainsrc": "./src/",
"projects": [],
"dependencies": {
"github.com/HashLoad/horse": "^2.0.0"
"github.com/dliocode/horse-utils-clientip": "^0.0.5",
"github.com/hashload/horse": "^v2.0.6"
}
}
8 changes: 4 additions & 4 deletions samples/boss-lock.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"hash": "d41d8cd98f00b204e9800998ecf8427e",
"updated": "2020-06-03T10:54:14.0172469-03:00",
"updated": "2020-12-24T12:33:51.3353566-03:00",
"installedModules": {
"github.com/hashload/horse": {
"name": "horse",
"version": "v2.0.1",
"hash": "a9e80dbc40536b989ad1089a85bb1c5b",
"version": "v2.0.6",
"hash": "cca1769dfab681cfd26ae8499f9045e1",
"artifacts": {},
"failed": false,
"changed": false
},
"github.com/hashload/horse-logger": {
"name": "horse-logger",
"version": "0.1.5",
"hash": "e8ce2dba3388af18152bf456394c98b6",
"hash": "0621e32582c643397c3b3c48aeffe33b",
"artifacts": {},
"failed": false,
"changed": false
Expand Down
1 change: 0 additions & 1 deletion samples/boss.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"mainsrc": "./",
"projects": [],
"dependencies": {
"github.com/hashload/horse": "^2.0.0",
"github.com/hashload/horse-logger": "^0.1.0"
}
}
215 changes: 206 additions & 9 deletions samples/samples.dproj

Large diffs are not rendered by default.

27 changes: 14 additions & 13 deletions src/Horse.Logger.pas
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
interface

uses
Horse, Horse.HTTP

{$IFDEF FPC }
, SysUtils, Classes, SyncObjs, Generics.Collections
SysUtils, Classes, SyncObjs, Generics.Collections,
{$ELSE}
, System.SysUtils, System.SyncObjs, , System.Classes, System.Generics.Collections
System.SysUtils, System.SyncObjs, System.Classes, System.Generics.Collections,
{$ENDIF}
;
Horse, Horse.HTTP, Horse.Utils.ClientIP;
type
{ THorseLoggerConfig }
THorseLoggerConfig = class
Expand Down Expand Up @@ -89,6 +89,7 @@ procedure Middleware(ARequest: THorseRequest; AResponse: THorseResponse; ANext:
LLog := THorseLogger.GetDefault.FHorseLoggerConfig.LogFormat;
LLog := LLog.Replace('${time}', THorseLogger.ValidateValue(LBeforeDateTime));
LLog := LLog.Replace('${execution_time}', THorseLogger.ValidateValue(LMilliSecondsBetween));
LLog := LLog.Replace('${request_clientip}', THorseLogger.ValidateValue(ClientIP(ARequest)));
LLog := LLog.Replace('${request_method}', THorseLogger.ValidateValue(LWebRequest.Method));
LLog := LLog.Replace('${request_version}', THorseLogger.ValidateValue(LWebRequest.ProtocolVersion));
LLog := LLog.Replace('${request_url}', THorseLogger.ValidateValue(LWebRequest.URL));
Expand Down Expand Up @@ -119,15 +120,15 @@ procedure Middleware(ARequest: THorseRequest; AResponse: THorseResponse; ANext:
LLog := LLog.Replace('${response_content_length}', THorseLogger.ValidateValue(LWebResponse.ContentLength));
LLog := LLog.Replace('${response_status}', THorseLogger.ValidateValue(LWebResponse.{$IF DEFINED(FPC)}Code.ToString(){$ELSE}StatusCode{$ENDIF}));
{$IF NOT DEFINED(FPC)}
LLog := LLog.Replace('${request_derived_from}', ValidateValue(LWebRequest.DerivedFrom));
LLog := LLog.Replace('${request_remote_ip}', ValidateValue(LWebRequest. RemoteIP));
LLog := LLog.Replace('${request_internal_path_info}', ValidateValue(LWebRequest.InternalPathInfo));
LLog := LLog.Replace('${request_raw_path_info}', ValidateValue(LWebRequest.RawPathInfo));
LLog := LLog.Replace('${request_cache_control}', ValidateValue(LWebRequest.CacheControl));
LLog := LLog.Replace('${response_realm}', ValidateValue(LWebResponse.Realm));
LLog := LLog.Replace('${response_log_message}', ValidateValue(LWebResponse.LogMessage));
LLog := LLog.Replace('${response_title}', ValidateValue(LWebResponse.Title));
LLog := LLog.Replace('${response_content_version}', ValidateValue(LWebResponse.ContentVersion));
LLog := LLog.Replace('${request_derived_from}', THorseLogger.ValidateValue(LWebRequest.DerivedFrom));
LLog := LLog.Replace('${request_remote_ip}', THorseLogger.ValidateValue(LWebRequest. RemoteIP));
LLog := LLog.Replace('${request_internal_path_info}', THorseLogger.ValidateValue(LWebRequest.InternalPathInfo));
LLog := LLog.Replace('${request_raw_path_info}', THorseLogger.ValidateValue(LWebRequest.RawPathInfo));
LLog := LLog.Replace('${request_cache_control}', THorseLogger.ValidateValue(LWebRequest.CacheControl));
LLog := LLog.Replace('${response_realm}', THorseLogger.ValidateValue(LWebResponse.Realm));
LLog := LLog.Replace('${response_log_message}', THorseLogger.ValidateValue(LWebResponse.LogMessage));
LLog := LLog.Replace('${response_title}', THorseLogger.ValidateValue(LWebResponse.Title));
LLog := LLog.Replace('${response_content_version}', THorseLogger.ValidateValue(LWebResponse.ContentVersion));
{$ENDIF}
THorseLogger.GetDefault.NewLog(LLog);
end;
Expand Down

0 comments on commit 8a0793e

Please sign in to comment.