forked from adaloveless/commonx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBetterHTTPReqResp.pas
65 lines (51 loc) · 1.52 KB
/
BetterHTTPReqResp.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
unit BetterHTTPReqResp;
interface
uses
HTTPClient_2019, classes, system.net.httpclient;
type
TBetterHTTPReqResp = class(THTTPReqResp)
private
FAcceptRanges: string;
FContentRange: string;
procedure HTTPWebNode_BeforePost(const HTTPReqResp: THTTPReqResp; Client: THTTPClient);
public
constructor Create(AOwner: TComponent); override;
property AcceptRanges: string read FAcceptRanges write FAcceptRanges;
property ContentRange: string read FContentRange write FContentRange;
end;
implementation
{ TBetterHTTPReqResp }
constructor TBetterHTTPReqResp.Create(AOwner: TComponent);
begin
inherited;
OnBeforePost := HTTPWebNode_BeforePost;
end;
{
TMyRIO = class(THTTPRIO)
public
constructor Create(AOwner: TComponent); override;
procedure HTTPWebNode_BeforePost(const AHTTPReqResp: THTTPReqResp;
AData: Pointer);
...
constructor TMyRIO.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
HTTPWebNode.OnBeforePost := HTTPWebNode_BeforePost;
end;
procedure TMyRIO.HTTPWebNode_BeforePost(const AHTTPReqResp:
THTTPReqResp; AData: Pointer);
const sCUSTOM_HEADER = 'X-Custom: value';
begin
HttpAddRequestHeaders(AData, PChar(sCUSTOM_HEADER),
Length(sCUSTOM_HEADER), HTTP_ADDREQ_FLAG_ADD);
end;
}
procedure TBetterHTTPReqResp.HTTPWebNode_BeforePost(
const HTTPReqResp: THTTPReqResp; Client: THTTPClient);
begin
if acceptranges <> '' then
client.CustomHeaders['Accept-Ranges'] := AcceptRanges;
if contentrange <> '' then
client.CustomHeaders['Content-Range'] := ContentRange;
end;
end.