Dieses Snippet stammt aus einem Code Sample zu Synapse.
Code: Alles auswählen
const
StrPropNames: array[0..12] of string=(
'Content-Type', // 0
'Content-Type', // 1
'Content-Disposition', // 2
'Content-Disposition', // 3
'Location', // 4
'Etag', // 5
'Host', // 6
'Referer', // 7
'User-Agent', // 8
'Vary', // 9
'WWW-Authenticate', //10 //!!!TODO
'Authorization', //11
'Content-Type' //12
);
function THttpRequest.GetStrProp(Index: integer): string;
var p: integer;
begin
Result:='';
if (Index>=0) and (Index<=High(StrPropNames)) then begin
Result:=Headers[StrPropNames[Index]]; // SynHttpSrv.pas(1959,32) Error: Incompatible type for arg no. 1: Got "AnsiString", expected "LongInt"
//
case Index of
1: begin
// BaseContentType... remove sub-type...
p:=Pos(';',Result);
if (p>0) then
Result:=TrimCopy(Result,1,p-1);
end;
3: begin
// TargetFileName, extract it:
// Content-Disposition: attachment; filename="Filename" also works without the "attachment"...
Result:=GetHeaderSubValue(Result,'filename')
end;
12: begin
// Boundary:
Result:=GetHeaderSubValue(Result,'boundary');
end;
end;
end;
end;
Armin.