forked from zamronypj/fano
/
FcgiBeginRequest.pas
102 lines (88 loc) · 2.67 KB
/
FcgiBeginRequest.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
{*!
* Fano Web Framework (https://fanoframework.github.io)
*
* @link https://github.com/fanoframework/fano
* @copyright Copyright (c) 2018 Zamrony P. Juhara
* @license https://github.com/fanoframework/fano/blob/master/LICENSE (MIT)
*}
unit FcgiBeginRequest;
interface
{$MODE OBJFPC}
{$H+}
uses
fastcgi,
StreamAdapterIntf,
FcgiBeginRequestIntf,
FcgiRecord;
type
(*!-----------------------------------------------
* Begin Request record (FCGI_BEGIN_REQUEST)
*
* @author Zamrony P. Juhara <zamronypj@yahoo.com>
*-----------------------------------------------*)
TFcgiBeginRequest = class(TFcgiRecord, IFcgiBeginRequest)
private
fFlag : byte;
fRole : byte;
public
constructor create(
const aVersion : byte;
const aType : byte;
const aRequestId : word;
const dataStream : IStreamAdapter;
const role : byte;
const flag: byte
);
constructor create(
const dataStream : IStreamAdapter;
const requestId : word;
const role : byte = FCGI_RESPONDER;
const flag: byte = 0
);
function keepConnection() : boolean;
function role() : byte;
end;
implementation
constructor TFcgiBeginRequest.create(
const aVersion : byte;
const aType : byte;
const aRequestId : word;
const dataStream : IStreamAdapter;
const role : byte;
const flag: byte
);
var beginRequestRec : FCGI_BeginRequestBody;
bytesToWrite : integer;
begin
inherited create(aVersion, aType, aRequestId, dataStream);
bytesToWrite := sizeOf(FCGI_BeginRequestBody);
beginRequestRec.role := role;
beginRequestRec.flags := flag;
beginRequestRec.reserved[0] := 0;
beginRequestRec.reserved[1] := 0;
beginRequestRec.reserved[2] := 0;
beginRequestRec.reserved[3] := 0;
beginRequestRec.reserved[4] := 0;
fContentData.writeBuffer(beginRequestRec, bytesToWrite);
fContentData.seek(0);
fFlag := flag;
fRole := role;
end;
constructor TFcgiBeginRequest.create(
const dataStream : IStreamAdapter;
const requestId : word;
const role : byte = FCGI_RESPONDER;
const flag: byte = 0
);
begin
create(FCGI_VERSION_1, FCGI_BEGIN_REQUEST, requestId, dataStream, role, flag);
end;
function TFcgiBeginRequest.keepConnection() : boolean;
begin
result := ((fFlag and FCGI_KEEP_CONN) = FCGI_KEEP_CONN);
end;
function TFcgiBeginRequest.role() : byte;
begin
result := fRole;
end;
end.