Skip to content

Commit f358fd1

Browse files
Moved username/password to http client rather than request object.
not sure why I put it there in the first place!
1 parent 41b97a4 commit f358fd1

3 files changed

Lines changed: 47 additions & 72 deletions

File tree

Source/VSoft.HttpClient.Request.pas

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ TRequest = class(TInterfacedObject, IHttpRequest)
3535
FEncoding : TEncoding;
3636
FForceFormData : boolean;
3737
FFollowRedirects : boolean;
38-
FUserName : string;
39-
FPassword : string;
40-
FProxyUserName : string;
41-
FProxyPassword : string;
4238

4339
FConnectionTimeout: Integer;
4440
FSendTimeout: Integer;
@@ -60,10 +56,6 @@ TRequest = class(TInterfacedObject, IHttpRequest)
6056
function GetSaveAsFile : string;
6157
function GetResource : string;
6258

63-
function GetUserName : string;
64-
function GetPassword : string;
65-
function GetProxyUserName : string;
66-
function GetProxyPassword : string;
6759
function GetConnectionTimeout : integer;
6860
function GetSendTimeout : integer;
6961
function GetResponseTimeout : integer;
@@ -77,10 +69,6 @@ TRequest = class(TInterfacedObject, IHttpRequest)
7769
procedure SetHttpMethod(value : THttpMethod);
7870
procedure SetSaveAsFile(const value : string);
7971
procedure SetResource(const value : string);
80-
procedure SetUserName(const value : string);
81-
procedure SetPassword(const value : string);
82-
procedure SetProxyUserName(const value : string);
83-
procedure SetProxyPassword(const value : string);
8472

8573
procedure SetConnectionTimeout(value : integer);
8674
procedure SetSendTimeout(value : integer);
@@ -147,10 +135,6 @@ TRequest = class(TInterfacedObject, IHttpRequest)
147135
property Resource : string read GetResource write SetResource;
148136
property ContentLength : Int64 read GetContentLength;
149137
property SaveAsFile : string read FSaveAsFile write FSaveAsFile;
150-
property UserName : string read FUserName write FUserName;
151-
property Passsword : string read FPassword write FPassword;
152-
property ProxyUserName : string read FProxyUserName write FProxyUserName;
153-
property ProxyPassword : string read FProxyPassword write FProxyPassword;
154138

155139
property ConnectionTimeout: Integer read FConnectionTimeout write FConnectionTimeout;
156140
property SendTimeout: Integer read FSendTimeout write FSendTimeout;
@@ -375,20 +359,6 @@ function TRequest.GetParameters: TStrings;
375359
result := FRequestParams;
376360
end;
377361

378-
function TRequest.GetPassword: string;
379-
begin
380-
result := FPassword;
381-
end;
382-
383-
function TRequest.GetProxyPassword: string;
384-
begin
385-
result := FProxyPassword;
386-
end;
387-
388-
function TRequest.GetProxyUserName: string;
389-
begin
390-
result := FProxyUserName;
391-
end;
392362

393363
function TRequest.GetResource: string;
394364
begin
@@ -416,11 +386,6 @@ function TRequest.GetUrlSegments: TStrings;
416386
result := FUrlSegments;
417387
end;
418388

419-
function TRequest.GetUserName: string;
420-
begin
421-
result := FUserName;
422-
end;
423-
424389

425390
procedure TRequest.SetAccept(const value: string);
426391
begin
@@ -462,21 +427,6 @@ procedure TRequest.SetHttpMethod(value: THttpMethod);
462427
FHttpMethod := value;
463428
end;
464429

465-
procedure TRequest.SetPassword(const value: string);
466-
begin
467-
FPassword := value;
468-
end;
469-
470-
procedure TRequest.SetProxyPassword(const value: string);
471-
begin
472-
FProxyPassword := value;
473-
end;
474-
475-
procedure TRequest.SetProxyUserName(const value: string);
476-
begin
477-
FProxyUserName := value;
478-
end;
479-
480430
procedure TRequest.SetResource(const value: string);
481431
begin
482432
FURI.Path := value;
@@ -497,10 +447,6 @@ procedure TRequest.SetSendTimeout(value: integer);
497447
FSendTimeout := value;
498448
end;
499449

500-
procedure TRequest.SetUserName(const value: string);
501-
begin
502-
FUserName := value;
503-
end;
504450

505451
function TRequest.WillFollowRedirects: IHttpRequest;
506452
begin

Source/VSoft.HttpClient.WinHttpClient.pas

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ THttpClient = class(THttpClientBase, IHttpClient, IHttpClientInternal)
2525
FAuthTyp : THttpAuthType;
2626
FUserName : string;
2727
FPassword : string;
28+
FProxyUserName : string;
29+
FProxyPassword : string;
30+
2831
FWaitEvent : TEvent;
2932
FCurrentRequest : IHttpRequest;
3033
FResponse : IHttpResponseInternal;
@@ -74,6 +77,13 @@ THttpClient = class(THttpClientBase, IHttpClient, IHttpClientInternal)
7477
function GetPassword : string;
7578
procedure SetUserName(const value : string);
7679
procedure SetPassword(const value : string);
80+
function GetProxyUserName : string;
81+
procedure SetProxyUserName(const value : string);
82+
83+
function GetProxyPassword : string;
84+
procedure SetProxyPassword(const value : string);
85+
86+
7787

7888
function GetUseHttp2 : boolean;
7989
procedure SetUseHttp2(const value : boolean);
@@ -92,6 +102,8 @@ THttpClient = class(THttpClientBase, IHttpClient, IHttpClientInternal)
92102

93103

94104

105+
106+
95107
function CreateRequest(const resource : string) : IHttpRequest;overload;
96108
function CreateRequest(const uri : IUri) : IHttpRequest;overload;
97109

@@ -301,6 +313,16 @@ function THttpClient.GetPassword: string;
301313
result := FPassword;
302314
end;
303315

316+
function THttpClient.GetProxyPassword: string;
317+
begin
318+
result := FProxyPassword;
319+
end;
320+
321+
function THttpClient.GetProxyUserName: string;
322+
begin
323+
result := FProxyUserName;
324+
end;
325+
304326
function THttpClient.GetResourceFromRequest(const request: IHttpRequest): string;
305327
var
306328
i : integer;
@@ -366,9 +388,9 @@ function THttpClient.DoAuthentication(hRequest : HINTERNET; dwAuthenticationSche
366388
case dwAuthTarget of
367389
WINHTTP_AUTH_TARGET_SERVER :
368390
begin
369-
if FCurrentRequest.UserName <> '' then
391+
if FUserName <> '' then
370392
begin
371-
if not WinHttpSetCredentials(hRequest, dwAuthTarget, dwAuthenticationScheme, PChar(FCurrentRequest.UserName), PChar(FCurrentRequest.Passsword),nil) then
393+
if not WinHttpSetCredentials(hRequest, dwAuthTarget, dwAuthenticationScheme, PChar(FUserName), PChar(FPassword),nil) then
372394
result := S_OK
373395
else
374396
result := GetLastError;
@@ -377,9 +399,9 @@ function THttpClient.DoAuthentication(hRequest : HINTERNET; dwAuthenticationSche
377399
end;
378400
WINHTTP_AUTH_TARGET_PROXY :
379401
begin
380-
if FCurrentRequest.ProxyUserName <> '' then
402+
if FProxyUserName <> '' then
381403
begin
382-
if WinHttpSetCredentials(hRequest, dwAuthTarget, dwAuthenticationScheme, PChar(FCurrentRequest.ProxyUserName), PChar(FCurrentRequest.ProxyPassword),nil) then
404+
if WinHttpSetCredentials(hRequest, dwAuthTarget, dwAuthenticationScheme, PChar(FProxyUserName), PChar(FProxyPassword),nil) then
383405
result := S_OK
384406
else
385407
result := GetLastError;
@@ -892,6 +914,16 @@ procedure THttpClient.SetPassword(const value: string);
892914
FPassword := value;
893915
end;
894916

917+
procedure THttpClient.SetProxyPassword(const value: string);
918+
begin
919+
FProxyPassword := value;
920+
end;
921+
922+
procedure THttpClient.SetProxyUserName(const value: string);
923+
begin
924+
FProxyUserName := value;
925+
end;
926+
895927
procedure THttpClient.SetResponseTimeout(const value: integer);
896928
begin
897929
FResponseTimeout := value;

Source/VSoft.HttpClient.pas

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ interface
8181
function GetSaveAsFile : string;
8282
function GetResource : string;
8383

84-
function GetUserName : string;
85-
function GetPassword : string;
86-
function GetProxyUserName : string;
87-
function GetProxyPassword : string;
8884
function GetConnectionTimeout : integer;
8985
function GetSendTimeout : integer;
9086
function GetResponseTimeout : integer;
@@ -98,10 +94,6 @@ interface
9894
procedure SetHttpMethod(value : THttpMethod);
9995
procedure SetSaveAsFile(const value : string);
10096
procedure SetResource(const value : string);
101-
procedure SetUserName(const value : string);
102-
procedure SetPassword(const value : string);
103-
procedure SetProxyUserName(const value : string);
104-
procedure SetProxyPassword(const value : string);
10597

10698
procedure SetConnectionTimeout(value : integer);
10799
procedure SetSendTimeout(value : integer);
@@ -163,10 +155,6 @@ interface
163155
property Resource : string read GetResource write SetResource;
164156
property ContentLength : Int64 read GetContentLength;
165157
property SaveAsFile : string read GetSaveAsFile write SetSaveAsFile;
166-
property UserName : string read GetUserName write SetUserName;
167-
property Passsword : string read GetPassword write SetPassword;
168-
property ProxyUserName : string read GetProxyUserName write SetProxyUserName;
169-
property ProxyPassword : string read GetProxyPassword write SetProxyPassword;
170158

171159
property ConnectionTimeout: Integer read GetConnectionTimeout write SetConnectionTimeout;
172160
property SendTimeout: Integer read GetSendTimeout write SetSendTimeout;
@@ -236,6 +224,13 @@ THttpClientBase = class(TInterfacedObject)
236224
function GetPassword : string;
237225
procedure SetPassword(const value : string);
238226

227+
function GetProxyUserName : string;
228+
procedure SetProxyUserName(const value : string);
229+
230+
function GetProxyPassword : string;
231+
procedure SetProxyPassword(const value : string);
232+
233+
239234
function GetConnectionTimeout : integer;
240235
procedure SetConnectionTimeout(const value : integer);
241236

@@ -263,8 +258,10 @@ THttpClientBase = class(TInterfacedObject)
263258
property AuthType : THttpAuthType read GetAuthType write SetAuthType;
264259
property BaseUri : string read GetBaseUri write SetBaseUri;
265260
property UserAgent : string read GetUserAgent write SetUserAgent;
266-
property UserName : string read GetUserName write SetUserName;
267-
property Password : string read GetPassword write SetPassword;
261+
property UserName : string read GetUserName write SetUserName;
262+
property Passsword : string read GetPassword write SetPassword;
263+
property ProxyUserName : string read GetProxyUserName write SetProxyUserName;
264+
property ProxyPassword : string read GetProxyPassword write SetProxyPassword;
268265

269266
property ConnectionTimeout: Integer read GetConnectionTimeout write SetConnectionTimeout;
270267
property SendTimeout: Integer read GetSendTimeout write SetSendTimeout;

0 commit comments

Comments
 (0)