Added simple FormField support
This commit is contained in:
parent
aa8c6d8b58
commit
610c1e4108
|
@ -97,6 +97,12 @@ Once the first none-empty line is unrecognized (no command found), the parser wi
|
|||
`Method <HTTP Method>`
|
||||
: This sets the method to be used for the call.
|
||||
|
||||
`FormField <key>=<value>`
|
||||
: Adds a key/value pair to the url-encoded-form-data body.
|
||||
The encoding will be done automatically!
|
||||
This can be repeated multiple times but will only be used when Method == POST.
|
||||
The Content-Type header is set automatically too.
|
||||
|
||||
`Call <URL>`
|
||||
: This prepares the actual call by providing the URL to be called.
|
||||
Variables in the form of `@<variablename>` are replaced accordingly.
|
||||
|
|
|
@ -40,6 +40,7 @@ type
|
|||
FParser: TJTemplateParser;
|
||||
FHttp: TFPHTTPClient;
|
||||
FContent: TStringList;
|
||||
FFormFields: TStringList;
|
||||
FFilters: TFilterList;
|
||||
FBeautify: Boolean;
|
||||
FURL: String;
|
||||
|
@ -52,6 +53,7 @@ type
|
|||
procedure CmdHeader(AHeader: String);
|
||||
procedure CmdBasicAuth(AData: String);
|
||||
procedure CmdHighlight(AData: String);
|
||||
procedure CmdFormField(AData: String);
|
||||
procedure ProcessCall(AURL: String);
|
||||
//Helper
|
||||
procedure WriteHelp;
|
||||
|
@ -192,6 +194,11 @@ begin
|
|||
Result := True;
|
||||
CmdHighlight(Copy(ALine, 11, Length(ALine)));
|
||||
end else
|
||||
if AnsiStartsStr('FormField ', ALine) then
|
||||
begin
|
||||
Result := True;
|
||||
CmdFormField(Copy(ALine, 11, Length(ALine)));
|
||||
end else
|
||||
if AnsiStartsStr('Call ', ALine) then
|
||||
begin
|
||||
Result := True;
|
||||
|
@ -270,6 +277,13 @@ begin
|
|||
FFilters.Add(THighlightFilter.Create(AData))
|
||||
end;
|
||||
|
||||
procedure TRestemplateApplication.CmdFormField(AData: String);
|
||||
begin
|
||||
FParser.Content := AData;
|
||||
FParser.Replace;
|
||||
FFormFields.Add(FParser.Content);
|
||||
end;
|
||||
|
||||
procedure TRestemplateApplication.ProcessCall(AURL: String);
|
||||
var
|
||||
s: String;
|
||||
|
@ -302,6 +316,10 @@ begin
|
|||
end;
|
||||
|
||||
try
|
||||
//Special handling for formdata
|
||||
if SameText('POST', FMethod) and (FFormFields.Count > 0) then
|
||||
FHttp.FormPost(AURL, FFormFields, response)
|
||||
else
|
||||
FHttp.HTTPMethod(FMethod, AURL, response, []);
|
||||
except
|
||||
on E: Exception do
|
||||
|
@ -456,6 +474,7 @@ begin
|
|||
|
||||
FSessionIni := TIniFile.Create(FConfigDir + 'session.ini');
|
||||
FContent := TStringList.Create;
|
||||
FFormFields := TStringList.Create;
|
||||
FHttp := TFPHTTPClient.Create(Self);
|
||||
FFilters := TFilterList.Create;
|
||||
FParser := TJTemplateParser.Create;
|
||||
|
@ -465,6 +484,7 @@ destructor TRestemplateApplication.Destroy;
|
|||
begin
|
||||
FSessionIni.Free;
|
||||
FContent.Free;
|
||||
FFormFields.Free;
|
||||
FHttp.Free;
|
||||
FFilters.Free;
|
||||
FParser.Free;
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
<VersionInfo>
|
||||
<UseVersionInfo Value="True"/>
|
||||
<MinorVersionNr Value="5"/>
|
||||
<StringTable LegalCopyright="Andreas Schneider" ProductName="restemplate" ProductVersion="0.5"/>
|
||||
<RevisionNr Value="1"/>
|
||||
<StringTable LegalCopyright="Andreas Schneider" ProductName="restemplate" ProductVersion="0.5.1"/>
|
||||
</VersionInfo>
|
||||
<BuildModes Count="2">
|
||||
<Item1 Name="Default" Default="True"/>
|
||||
|
|
Loading…
Reference in New Issue