Quellcode durchsuchen

Option zum automatischen formatieren der response

Simon Grossenbacher vor 6 Jahren
Ursprung
Commit
454fdac238
9 geänderte Dateien mit 119 neuen und 75 gelöschten Zeilen
  1. 16 8
      Example Config.rdproj
  2. BIN
      RESTDebugger.exe
  3. BIN
      libeay32.dll
  4. 10 11
      prj/RESTDebugger.dproj
  5. BIN
      prj/RESTDebugger.res
  6. 6 6
      prj/RESTDebugger.stat
  7. 56 38
      src/_frmMain.dfm
  8. 31 12
      src/_frmMain.pas
  9. BIN
      ssleay32.dll

+ 16 - 8
Example Config.rdproj

@@ -13,7 +13,8 @@
 		"PostDataContentType": "application/json",
 		"UseBasicAuth": false,
 		"AuthUsername": "",
-		"AuthPassword": ""
+		"AuthPassword": "",
+		"ResponseAutoFormat": false
 	},
 	"Preset_7d37b798c22748eebf92ffa281ba982a": {
 		"BaseURL": "https://httpbin.org/headers",
@@ -24,7 +25,8 @@
 		"PostDataContentType": "application/json",
 		"UseBasicAuth": false,
 		"AuthUsername": "",
-		"AuthPassword": ""
+		"AuthPassword": "",
+		"ResponseAutoFormat": false
 	},
 	"Preset_777045dda27d466fab6c051d3e8094e8": {
 		"BaseURL": "https://httpbin.org/basic-auth/user/pwd",
@@ -35,7 +37,8 @@
 		"PostDataContentType": "application/json",
 		"UseBasicAuth": true,
 		"AuthUsername": "3f0k+uBHWf2sPtwW4tYMUA==",
-		"AuthPassword": "C35R83xuSqKQ93OJME1BZA=="
+		"AuthPassword": "C35R83xuSqKQ93OJME1BZA==",
+		"ResponseAutoFormat": false
 	},
 	"Preset_a0745bab53eb4c78a6034f1a9d4559de": {
 		"BaseURL": "https://httpbin.org/get",
@@ -46,7 +49,8 @@
 		"PostDataContentType": "application/json",
 		"UseBasicAuth": false,
 		"AuthUsername": "",
-		"AuthPassword": ""
+		"AuthPassword": "",
+		"ResponseAutoFormat": false
 	},
 	"Preset_292047e733934bc48429c4d746cae53a": {
 		"BaseURL": "https://httpbin.org/post",
@@ -57,7 +61,8 @@
 		"PostDataContentType": "application/json",
 		"UseBasicAuth": false,
 		"AuthUsername": "",
-		"AuthPassword": ""
+		"AuthPassword": "",
+		"ResponseAutoFormat": false
 	},
 	"Preset_c02b437c22474cf7b44a96c72f430f18": {
 		"BaseURL": "http://jsonplaceholder.typicode.com/posts/1",
@@ -68,7 +73,8 @@
 		"PostDataContentType": "application/json",
 		"UseBasicAuth": false,
 		"AuthUsername": "",
-		"AuthPassword": ""
+		"AuthPassword": "",
+		"ResponseAutoFormat": false
 	},
 	"Preset_9609fe373b9b4865a2ea83a3dd35be30": {
 		"BaseURL": "https://httpbin.org/put",
@@ -79,7 +85,8 @@
 		"PostDataContentType": "application/json",
 		"UseBasicAuth": false,
 		"AuthUsername": "",
-		"AuthPassword": ""
+		"AuthPassword": "",
+		"ResponseAutoFormat": false
 	},
 	"Preset_cbbcebba6f30425caec540f517cb3524": {
 		"BaseURL": "https://httpbin.org/patch",
@@ -90,6 +97,7 @@
 		"PostDataContentType": "application/json",
 		"UseBasicAuth": false,
 		"AuthUsername": "",
-		"AuthPassword": ""
+		"AuthPassword": "",
+		"ResponseAutoFormat": false
 	}
 }

BIN
RESTDebugger.exe


BIN
libeay32.dll


+ 10 - 11
prj/RESTDebugger.dproj

@@ -86,9 +86,9 @@
     <PropertyGroup Condition="'$(Base_Win64)'!=''">
         <UWP_DelphiLogo44>$(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png</UWP_DelphiLogo44>
         <UWP_DelphiLogo150>$(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png</UWP_DelphiLogo150>
-        <VerInfo_Keys>FileVersion=1.1.9.40;ProductVersion=1.0.0.0;ProgramID=com.embarcadero.$(MSBuildProjectName);FileDescription=$(MSBuildProjectName);ProductName=$(MSBuildProjectName)</VerInfo_Keys>
-        <VerInfo_Release>9</VerInfo_Release>
-        <VerInfo_Build>40</VerInfo_Build>
+        <VerInfo_Keys>FileVersion=1.1.10.45;ProductVersion=1.0.0.0;ProgramID=com.embarcadero.$(MSBuildProjectName);FileDescription=$(MSBuildProjectName);ProductName=$(MSBuildProjectName)</VerInfo_Keys>
+        <VerInfo_Release>10</VerInfo_Release>
+        <VerInfo_Build>45</VerInfo_Build>
         <Icon_MainIcon>RESTDebugger_Icon.ico</Icon_MainIcon>
         <VerInfo_Locale>1033</VerInfo_Locale>
         <DCC_Namespace>Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;$(DCC_Namespace)</DCC_Namespace>
@@ -115,9 +115,9 @@
     </PropertyGroup>
     <PropertyGroup Condition="'$(Cfg_1_Win64)'!=''">
         <BT_BuildType>Debug</BT_BuildType>
-        <VerInfo_Keys>FileVersion=1.1.9.40;ProductVersion=1.0.0.0;ProgramID=com.embarcadero.$(MSBuildProjectName);FileDescription=$(MSBuildProjectName);ProductName=$(MSBuildProjectName)</VerInfo_Keys>
-        <VerInfo_Build>40</VerInfo_Build>
-        <VerInfo_Release>9</VerInfo_Release>
+        <VerInfo_Keys>FileVersion=1.1.10.45;ProductVersion=1.0.0.0;ProgramID=com.embarcadero.$(MSBuildProjectName);FileDescription=$(MSBuildProjectName);ProductName=$(MSBuildProjectName)</VerInfo_Keys>
+        <VerInfo_Build>45</VerInfo_Build>
+        <VerInfo_Release>10</VerInfo_Release>
         <VerInfo_Locale>1033</VerInfo_Locale>
         <AppEnableHighDPI>true</AppEnableHighDPI>
         <AppEnableRuntimeThemes>true</AppEnableRuntimeThemes>
@@ -140,9 +140,9 @@
     </PropertyGroup>
     <PropertyGroup Condition="'$(Cfg_2_Win64)'!=''">
         <BT_BuildType>Debug</BT_BuildType>
-        <VerInfo_Keys>FileVersion=1.1.9.40;ProductVersion=1.0.0.0;ProgramID=com.embarcadero.$(MSBuildProjectName);FileDescription=$(MSBuildProjectName);ProductName=$(MSBuildProjectName)</VerInfo_Keys>
-        <VerInfo_Release>9</VerInfo_Release>
-        <VerInfo_Build>40</VerInfo_Build>
+        <VerInfo_Keys>FileVersion=1.1.10.45;ProductVersion=1.0.0.0;ProgramID=com.embarcadero.$(MSBuildProjectName);FileDescription=$(MSBuildProjectName);ProductName=$(MSBuildProjectName)</VerInfo_Keys>
+        <VerInfo_Release>10</VerInfo_Release>
+        <VerInfo_Build>45</VerInfo_Build>
         <AppEnableHighDPI>true</AppEnableHighDPI>
         <AppEnableRuntimeThemes>true</AppEnableRuntimeThemes>
         <VerInfo_Locale>1033</VerInfo_Locale>
@@ -186,10 +186,9 @@
                     <Source Name="MainSource">RESTDebugger.dpr</Source>
                 </Source>
                 <Excluded_Packages>
+                    <Excluded_Packages Name="C:\dev\IDEAddons\Delphi10.2Tokyo\FixInsight\FixInsight_10_2.bpl">Datei C:\dev\IDEAddons\Delphi10.2Tokyo\FixInsight\FixInsight_10_2.bpl nicht gefunden</Excluded_Packages>
                     <Excluded_Packages Name="$(BDSBIN)\dcloffice2k250.bpl">Microsoft Office 2000 Beispiele für gekapselte Komponenten für Automatisierungsserver</Excluded_Packages>
                     <Excluded_Packages Name="$(BDSBIN)\dclofficexp250.bpl">Microsoft Office XP Beispiele für gekapselte Komponenten für Automation Server</Excluded_Packages>
-                    <Excluded_Packages Name="C:\dev\_components\FastReport5\LibD25\dclfrxIBX25.bpl">FastReport 5.0 IBX Components</Excluded_Packages>
-                    <Excluded_Packages Name="C:\dev\_components\FastReport5\LibD25\dclfsIBX25.bpl">FastScript 1.9 IBX Components</Excluded_Packages>
                 </Excluded_Packages>
             </Delphi.Personality>
             <Deployment Version="3">

BIN
prj/RESTDebugger.res


+ 6 - 6
prj/RESTDebugger.stat

@@ -1,10 +1,10 @@
 [Stats]
-EditorSecs=26784
-DesignerSecs=6081
-InspectorSecs=3357
-CompileSecs=1191675
-OtherSecs=6067
+EditorSecs=27668
+DesignerSecs=6367
+InspectorSecs=3599
+CompileSecs=1262160
+OtherSecs=6692
 StartTime=27.10.2016 18:27:37
 RealKeys=0
 EffectiveKeys=0
-DebugSecs=17485
+DebugSecs=18644

+ 56 - 38
src/_frmMain.dfm

@@ -86,63 +86,59 @@ object frmMain: TfrmMain
       BarManager = dxBarManager
     end
   end
-  object dxStatusBar: TdxStatusBar
+  object dxStatusBarResponse: TdxStatusBar
     Left = 0
-    Top = 910
+    Top = 890
     Width = 725
     Height = 20
     Panels = <
       item
         PanelStyleClassName = 'TdxStatusBarTextPanelStyle'
-        Text = 'Copyright '#169' by Simnet'
+        Text = 'Response Time: 10'#39'000 ms'
         Width = 160
       end
       item
         PanelStyleClassName = 'TdxStatusBarTextPanelStyle'
         MinWidth = 100
-        Text = 'Response Time: 10'#39'000 ms'
-        Width = 150
-      end
-      item
-        PanelStyleClassName = 'TdxStatusBarTextPanelStyle'
         Text = 'Response Code: 200'
         Width = 110
       end
       item
         PanelStyleClassName = 'TdxStatusBarTextPanelStyle'
-        Text = 'Default project loaded.'
+        Text = 'Response Content: application/json'
+        Width = 200
       end>
+    SizeGrip = False
     Font.Charset = DEFAULT_CHARSET
     Font.Color = clWindowText
     Font.Height = -11
     Font.Name = 'Tahoma'
     Font.Style = []
+    ExplicitTop = 880
   end
   object PageControlResponse: TcxPageControl
     Left = 0
     Top = 458
     Width = 725
-    Height = 452
+    Height = 432
     Align = alClient
     TabOrder = 3
     Properties.ActivePage = tabContent
     Properties.CustomButtons.Buttons = <>
-    ClientRectBottom = 450
+    ExplicitHeight = 452
+    ClientRectBottom = 430
     ClientRectLeft = 2
     ClientRectRight = 723
     ClientRectTop = 26
     object tabContent: TcxTabSheet
       Caption = 'Response Content'
       ImageIndex = 0
-      ExplicitLeft = 0
-      ExplicitTop = 0
-      ExplicitWidth = 0
-      ExplicitHeight = 0
+      ExplicitHeight = 424
       object EditorContent: TSynEdit
         Left = 0
-        Top = 0
+        Top = 31
         Width = 721
-        Height = 424
+        Height = 373
         Align = alClient
         Font.Charset = DEFAULT_CHARSET
         Font.Color = clWindowText
@@ -166,20 +162,35 @@ object frmMain: TfrmMain
         TabWidth = 2
         WantTabs = True
         FontSmoothing = fsmNone
+        ExplicitLeft = 3
+        ExplicitTop = 175
+        ExplicitHeight = 225
+      end
+      object Panel2: TPanel
+        Left = 0
+        Top = 0
+        Width = 721
+        Height = 31
+        Align = alTop
+        BevelOuter = bvNone
+        TabOrder = 1
+        object chkResponseAutoformat: TcxCheckBox
+          Left = 8
+          Top = 6
+          Caption = 'Auto format XML and JSON response'
+          TabOrder = 0
+        end
       end
     end
     object tabHeaders: TcxTabSheet
       Caption = 'Response Headers'
       ImageIndex = 1
-      ExplicitLeft = 0
-      ExplicitTop = 0
-      ExplicitWidth = 0
-      ExplicitHeight = 0
+      ExplicitHeight = 424
       object EditorResponseHeaders: TSynEdit
         Left = 0
         Top = 0
         Width = 721
-        Height = 424
+        Height = 404
         Align = alClient
         Font.Charset = DEFAULT_CHARSET
         Font.Color = clWindowText
@@ -203,6 +214,7 @@ object frmMain: TfrmMain
         TabWidth = 2
         WantTabs = True
         FontSmoothing = fsmNone
+        ExplicitHeight = 424
       end
     end
   end
@@ -370,10 +382,6 @@ object frmMain: TfrmMain
       object tabURLParams: TcxTabSheet
         Caption = 'URL Parameters'
         ImageIndex = 0
-        ExplicitLeft = 0
-        ExplicitTop = 0
-        ExplicitWidth = 0
-        ExplicitHeight = 0
         object Panel3: TPanel
           Left = 0
           Top = 0
@@ -426,10 +434,6 @@ object frmMain: TfrmMain
       object cxTabSheet2: TcxTabSheet
         Caption = 'Extra Headers'
         ImageIndex = 1
-        ExplicitLeft = 0
-        ExplicitTop = 0
-        ExplicitWidth = 0
-        ExplicitHeight = 0
         object Panel4: TPanel
           Left = 0
           Top = 0
@@ -481,10 +485,6 @@ object frmMain: TfrmMain
       object cxTabSheet3: TcxTabSheet
         Caption = 'Authentication'
         ImageIndex = 3
-        ExplicitLeft = 0
-        ExplicitTop = 0
-        ExplicitWidth = 0
-        ExplicitHeight = 0
         object Label9: TLabel
           Left = 15
           Top = 47
@@ -521,10 +521,6 @@ object frmMain: TfrmMain
       object tabPostData: TcxTabSheet
         Caption = 'Post Data'
         ImageIndex = 2
-        ExplicitLeft = 0
-        ExplicitTop = 0
-        ExplicitWidth = 0
-        ExplicitHeight = 0
         object Panel5: TPanel
           Left = 0
           Top = 0
@@ -624,6 +620,28 @@ object frmMain: TfrmMain
     AlignSplitter = salBottom
     Control = pnlHeader
   end
+  object dxStatusBarApp: TdxStatusBar
+    Left = 0
+    Top = 910
+    Width = 725
+    Height = 20
+    Panels = <
+      item
+        PanelStyleClassName = 'TdxStatusBarTextPanelStyle'
+        Text = 'Copyright '#169' by Simnet'
+        Width = 160
+      end
+      item
+        PanelStyleClassName = 'TdxStatusBarTextPanelStyle'
+        Text = 'Default project loaded.'
+      end>
+    Font.Charset = DEFAULT_CHARSET
+    Font.Color = clWindowText
+    Font.Height = -11
+    Font.Name = 'Tahoma'
+    Font.Style = []
+    ExplicitTop = 900
+  end
   object OpenDialog: TOpenDialog
     Filter = 'REST Debugger Project (*.rdproj)|*.rdproj'
     Options = [ofHideReadOnly, ofFileMustExist, ofEnableSizing]

+ 31 - 12
src/_frmMain.pas

@@ -29,7 +29,7 @@ type
     Label1: TLabel;
     Image: TImage;
     SSLIOHandlerSocketOpenSSL: TIdSSLIOHandlerSocketOpenSSL;
-    dxStatusBar: TdxStatusBar;
+    dxStatusBarResponse: TdxStatusBar;
     dxBarManager: TdxBarManager;
     dxBarManagerBar1: TdxBar;
     dxBarSubItem3: TdxBarSubItem;
@@ -108,6 +108,9 @@ type
     SynEditSearch: TSynEditSearch;
     SynEditRegexSearch: TSynEditRegexSearch;
     cxSplitter1: TcxSplitter;
+    dxStatusBarApp: TdxStatusBar;
+    Panel2: TPanel;
+    chkResponseAutoformat: TcxCheckBox;
     procedure FormShow(Sender: TObject);
     procedure FormCreate(Sender: TObject);
     procedure FormDestroy(Sender: TObject);
@@ -669,8 +672,9 @@ begin
       ShowError(FHTTP.ResponseText);
     end;
   except
-    on E: Exception do
+    on E: EIdHTTPProtocolException do
     begin
+      dmy := E.ErrorMessage;
       ShowError(E.Message);
     end;
   end;
@@ -701,8 +705,9 @@ begin
         ShowError(FHTTP.ResponseText);
       end;
     except
-      on E: Exception do
+      on E: EIdHTTPProtocolException do
       begin
+        dmy := E.ErrorMessage;
         ShowError(E.Message);
       end;
     end;
@@ -1035,7 +1040,7 @@ end;
 
 procedure TfrmMain.FormShow(Sender: TObject);
 begin
-  dxStatusBar.Panels[0].Text := 'Copyright © by Simnet ' + FormatDateTime('yyyy', now);
+  dxStatusBarApp.Panels[0].Text := 'Copyright © by Simnet ' + FormatDateTime('yyyy', now);
 
   Left := MainConfig.ReadInteger('MainWindowPos', 'Left', Round((Screen.Width - Width) div 2));
 
@@ -1073,9 +1078,9 @@ begin
   EditorContent.Lines.Clear;
   EditorResponseHeaders.Lines.Clear;
 
-  dxStatusBar.Panels[1].Text := '';
-  dxStatusBar.Panels[2].Text := '';
-
+  dxStatusBarResponse.Panels[0].Text := '';
+  dxStatusBarResponse.Panels[1].Text := '';
+  dxStatusBarResponse.Panels[2].Text := '';
 
   gbSearchBackwards := MainConfig.ReadBool('Search', 'gbSearchBackwards', gbSearchBackwards);
   gbSearchCaseSensitive := MainConfig.ReadBool('Search', 'gbSearchCaseSensitive', gbSearchCaseSensitive);
@@ -1165,6 +1170,7 @@ begin
     EditorExtraHeaders.Lines.Text := FProjectConfig.ReadString(preset, 'ExtraHeaders');
     EditorPostData.Lines.Text := FProjectConfig.ReadString(preset, 'PostData');
     comboPostContentType.Text := FProjectConfig.ReadString(preset, 'PostDataContentType', 'application/json');
+    chkResponseAutoformat.Checked := FProjectConfig.ReadBool(preset, 'ResponseAutoFormat', false);
 
     chkUseBasicAuth.Checked := FProjectConfig.ReadBool(preset, 'UseBasicAuth');
     edtAuthUsername.Text := TEncryptStr.DecryptString(FProjectConfig.ReadString(preset, 'AuthUsername'));
@@ -1181,12 +1187,12 @@ var
 begin
   if FIsTempProjectLoaded then
   begin
-    dxStatusBar.Panels[3].Text := 'Default project loaded.';
+    dxStatusBarApp.Panels[1].Text := 'Default project loaded.';
     Caption := 'Simnet REST Debugger';
   end
   else
   begin
-    dxStatusBar.Panels[3].Text := 'Loaded project: ' + FActiveProject;
+    dxStatusBarApp.Panels[1].Text := 'Loaded project: ' + FActiveProject;
     Caption := ExtractFileName(FActiveProject) + ' - Simnet REST Debugger';
     MainConfig.WriteString('Project', 'LastUsed', FActiveProject);
   end;
@@ -1430,15 +1436,27 @@ begin
         DoGETRequest(mtDELETE);
       end;
     finally
+      ActiveEditor := EditorContent;
+      EditorContent.SetFocus;
 
       if Pos('application/json', FHTTP.Response.ContentType) > 0 then
       begin
         EditorContent.Highlighter := SynJSONSyn;
+
+        if chkResponseAutoformat.Checked then
+        begin
+          pmnuFormatJsonContentClick(nil);
+        end;
       end
       else
       if Pos('text/xml', FHTTP.Response.ContentType) > 0 then
       begin
         EditorContent.Highlighter := SynXMLSyn;
+
+        if chkResponseAutoformat.Checked then
+        begin
+          pmnuFormatXMLClick(nil);
+        end;
       end
       else
       if Pos('text/html', FHTTP.Response.ContentType) > 0 then
@@ -1450,11 +1468,11 @@ begin
         EditorContent.Highlighter := nil;
       end;
 
-      EditorContent.SetFocus;
 
 
-      dxStatusBar.Panels[1].Text := FormatFloat('Response Time: 0, ms', GetTickCount - tick);
-      dxStatusBar.Panels[2].Text := 'Response Code: ' + FHTTP.ResponseCode.ToString;
+      dxStatusBarResponse.Panels[0].Text := FormatFloat('Response Time: 0, ms', GetTickCount - tick);
+      dxStatusBarResponse.Panels[1].Text := 'Response Code: ' + FHTTP.ResponseCode.ToString;
+      dxStatusBarResponse.Panels[2].Text := 'Response Content: ' + FHTTP.Response.ContentType;
       Screen.Cursor := crDefault;
     end;
   finally
@@ -1477,6 +1495,7 @@ begin
     FProjectConfig.WriteString(preset, 'PostData', EditorPostData.Lines.Text);
     FProjectConfig.WriteString(preset, 'ExtraHeaders', EditorExtraHeaders.Lines.Text);
     FProjectConfig.WriteString(preset, 'PostDataContentType', comboPostContentType.Text);
+    FProjectConfig.WriteBool(preset, 'ResponseAutoFormat', chkResponseAutoformat.Checked);
 
     FProjectConfig.WriteBool(preset, 'UseBasicAuth', chkUseBasicAuth.Checked);
     FProjectConfig.WriteString(preset, 'AuthUsername', TEncryptStr.EncryptString(edtAuthUsername.Text));

BIN
ssleay32.dll