From 3838fe897187a3a7850da6604bf9ac5556f31724 Mon Sep 17 00:00:00 2001 From: Martin Schweizer Date: Fri, 12 Mar 2021 16:31:29 +0100 Subject: [PATCH] Add PostData to LoadURLOptions to allow http-posts in LoadURL calls Enable the possibility to post data to external Url's with the BrowserWindow.LoadURL function. The post data is provided through LoadURLOptions --- ElectronNET.API/Entities/Blob.cs | 18 ++++++++++++ ElectronNET.API/Entities/IPostData.cs | 16 ++++++++++ ElectronNET.API/Entities/LoadURLOptions.cs | 6 ++++ ElectronNET.API/Entities/UploadFile.cs | 34 ++++++++++++++++++++++ ElectronNET.API/Entities/UploadRawData.cs | 18 ++++++++++++ 5 files changed, 92 insertions(+) create mode 100644 ElectronNET.API/Entities/Blob.cs create mode 100644 ElectronNET.API/Entities/IPostData.cs create mode 100644 ElectronNET.API/Entities/UploadFile.cs create mode 100644 ElectronNET.API/Entities/UploadRawData.cs diff --git a/ElectronNET.API/Entities/Blob.cs b/ElectronNET.API/Entities/Blob.cs new file mode 100644 index 00000000..e1a81b0d --- /dev/null +++ b/ElectronNET.API/Entities/Blob.cs @@ -0,0 +1,18 @@ +namespace ElectronNET.API.Entities +{ + /// + /// + /// + public class Blob : IPostData + { + /// + /// The object represents a Blob + /// + public string Type { get; } = "blob"; + + /// + /// The UUID of the Blob being uploaded + /// + public string BlobUUID { get; set; } + } +} \ No newline at end of file diff --git a/ElectronNET.API/Entities/IPostData.cs b/ElectronNET.API/Entities/IPostData.cs new file mode 100644 index 00000000..a8c9612e --- /dev/null +++ b/ElectronNET.API/Entities/IPostData.cs @@ -0,0 +1,16 @@ +namespace ElectronNET.API.Entities +{ + /// + /// Interface to use Electrons PostData Object + /// + public interface IPostData + { + /// + /// One of the following: + /// rawData - The data is available as a Buffer, in the rawData field. + /// file - The object represents a file. The filePath, offset, length and modificationTime fields will be used to describe the file. + /// blob - The object represents a Blob. The blobUUID field will be used to describe the Blob. + /// + public string Type { get; } + } +} \ No newline at end of file diff --git a/ElectronNET.API/Entities/LoadURLOptions.cs b/ElectronNET.API/Entities/LoadURLOptions.cs index 606a262b..f4e14781 100644 --- a/ElectronNET.API/Entities/LoadURLOptions.cs +++ b/ElectronNET.API/Entities/LoadURLOptions.cs @@ -26,5 +26,11 @@ public class LoadURLOptions /// Extra headers for the request. /// public string ExtraHeaders { get; set; } + + /// + /// PostData Object for the request. + /// Can be , or + /// + public IPostData[] PostData { get; set; } } } \ No newline at end of file diff --git a/ElectronNET.API/Entities/UploadFile.cs b/ElectronNET.API/Entities/UploadFile.cs new file mode 100644 index 00000000..adff7df8 --- /dev/null +++ b/ElectronNET.API/Entities/UploadFile.cs @@ -0,0 +1,34 @@ +namespace ElectronNET.API.Entities +{ + /// + /// + /// + public class UploadFile : IPostData + { + /// + /// The object represents a file. + /// + public string Type { get; } = "file"; + + /// + /// The path of the file being uploaded. + /// + public string FilePath { get; set; } + + /// + /// The offset from the beginning of the file being uploaded, in bytes. Defaults to 0. + /// + public long Offset { get; set; } = 0; + + /// + /// The length of the file being uploaded, . Defaults to 0. + /// If set to -1, the whole file will be uploaded. + /// + public long Length { get; set; } = 0; + + /// + /// The modification time of the file represented by a double, which is the number of seconds since the UNIX Epoch (Jan 1, 1970) + /// + public double ModificationTime { get; set; } + } +} \ No newline at end of file diff --git a/ElectronNET.API/Entities/UploadRawData.cs b/ElectronNET.API/Entities/UploadRawData.cs new file mode 100644 index 00000000..d0a98de6 --- /dev/null +++ b/ElectronNET.API/Entities/UploadRawData.cs @@ -0,0 +1,18 @@ +namespace ElectronNET.API.Entities +{ + /// + /// + /// + public class UploadRawData : IPostData + { + /// + /// The data is available as a Buffer, in the rawData field. + /// + public string Type { get; } = "rawData"; + + /// + /// The raw bytes of the post data in a Buffer. + /// + public byte[] Bytes { get; set; } + } +} \ No newline at end of file