diff --git a/FsHttp.sln b/FsHttp.sln index 15809390..4b81c764 100644 --- a/FsHttp.sln +++ b/FsHttp.sln @@ -17,6 +17,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestWebServer", "src\TestWe EndProject Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Tests", "src\Tests\Tests.fsproj", "{63A6AF47-CB3F-4DBA-A16E-B66D6EFA3573}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CsHttp", "src\CsHttp\CsHttp.csproj", "{0A344D22-8F8C-4C3D-AE79-28ED87DFC793}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -47,6 +49,10 @@ Global {63A6AF47-CB3F-4DBA-A16E-B66D6EFA3573}.Debug|Any CPU.Build.0 = Debug|Any CPU {63A6AF47-CB3F-4DBA-A16E-B66D6EFA3573}.Release|Any CPU.ActiveCfg = Release|Any CPU {63A6AF47-CB3F-4DBA-A16E-B66D6EFA3573}.Release|Any CPU.Build.0 = Release|Any CPU + {0A344D22-8F8C-4C3D-AE79-28ED87DFC793}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0A344D22-8F8C-4C3D-AE79-28ED87DFC793}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0A344D22-8F8C-4C3D-AE79-28ED87DFC793}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0A344D22-8F8C-4C3D-AE79-28ED87DFC793}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -58,6 +64,7 @@ Global {1163EF7E-1845-4D2A-8C3F-8691618500DF} = {13B4B071-F3F1-4E38-93E4-CFA72611A84F} {E7E326FD-1D66-4DBD-AB60-D006D3B77244} = {13B4B071-F3F1-4E38-93E4-CFA72611A84F} {63A6AF47-CB3F-4DBA-A16E-B66D6EFA3573} = {13B4B071-F3F1-4E38-93E4-CFA72611A84F} + {0A344D22-8F8C-4C3D-AE79-28ED87DFC793} = {13B4B071-F3F1-4E38-93E4-CFA72611A84F} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {490D0829-D4E3-4267-8132-14A5B0C9D347} diff --git a/src/CsHttp/Class1.cs b/src/CsHttp/Class1.cs new file mode 100644 index 00000000..7b4e9b65 --- /dev/null +++ b/src/CsHttp/Class1.cs @@ -0,0 +1,103 @@ +using System; +using System.Net; +using FsHttp; +using Microsoft.FSharp.Collections; +using Microsoft.FSharp.Core; +using static FsHttp.Domain; +using static FsHttp.DslCE; + +#if NETSTANDARD2_0 || NETSTANDARD2_1 +using UnifiedHandler = System.Net.Http.HttpClientHandler; + +#else +using UnifiedHandler = System.Net.Http.SocketsHttpHandler; +#endif + +namespace CsHttp; + +public record HttpRequest +{ + internal string Method { get; private set; } + internal string Url { get; private set; } + + public string GET + { + set + { + Method = "GET"; + Url = value; + } + } + + public IToRequest Configure(Func transformer) + { + // var config = transformer(Defaults.defaultConfig); + var ctx = Dsl.Http.get(""); + Dsl.Config.update(FuncConvert.ToFSharpFunc((Config cfg) => transformer(cfg)), ctx); + + return ctx; + } +} + +public static class HttpRequestExtensions +{ + public static HttpRequest Http => new(); +} + +public static class Test +{ + public static void Main() + { + var request = + HttpRequestExtensions.Http with { GET = "https://example.com" }; + } +} + +public static class ConfigExtensions +{ + // TODO: Remove FsHttp.CSharp + + public static Config IgnoreCertIssues(this Config config) => + Dsl.Config.With.ignoreCertIssues(config); + + public static Config Timeout(this Config config, TimeSpan value) => + Dsl.Config.With.timeout(value, config); + + public static Config TimeoutInSeconds(this Config config, int value) => + Dsl.Config.With.timeoutInSeconds(value, config); + + public static Config SetHttpClientFactory( + this Config config, + Func httpClientFactory) => + Dsl.Config.With.setHttpClientFactory(FuncConvert.FromFunc(httpClientFactory), config); + + public static Config TransformHttpClient(this Config config, Func transformer) => + Dsl.Config.With.transformHttpClient(FuncConvert.FromFunc(transformer), config); + + public static Config TransformHttpRequestMessage( + this Config config, + Func transformer) => + Dsl.Config.With.transformHttpRequestMessage(FuncConvert.FromFunc(transformer), config); + + public static Config TransformHttpClientHandler( + this Config config, + Func transformer) => + Dsl.Config.With.transformHttpClientHandler(FuncConvert.FromFunc(transformer), config); + + public static Config Proxy(this Config config, string url) => + Dsl.Config.With.proxy(url, config); + + public static Config ProxyWithCredentials(this Config config, string url, ICredentials credentials) => + Dsl.Config.With.proxyWithCredentials(url, credentials, config); + + public static Config DecompressionMethods( + this Config config, + IReadOnlyCollection decompressionMethods) => + Dsl.Config.With.decompressionMethods(SeqModule.ToList(decompressionMethods), config); + + public static Config NoDecompression(this Config config) => + Dsl.Config.With.noDecompression(config); + + public static Config CancellationToken(this Config config, CancellationToken cancellationToken) => + Dsl.Config.With.cancellationToken(cancellationToken, config); +} diff --git a/src/CsHttp/CsHttp.csproj b/src/CsHttp/CsHttp.csproj new file mode 100644 index 00000000..42699474 --- /dev/null +++ b/src/CsHttp/CsHttp.csproj @@ -0,0 +1,18 @@ + + + + netstandard2.0;netstandard2.1;net6.0;net7.0;net8.0 + enable + enable + 12.0 + + + + + + + + + + + diff --git a/src/CsHttp/Test.cs b/src/CsHttp/Test.cs new file mode 100644 index 00000000..6ca2aad2 --- /dev/null +++ b/src/CsHttp/Test.cs @@ -0,0 +1,14 @@ +// namespace CsHttp; + +// using static Http; + +// public static class Test +// { +// public static void Main() +// { +// var request = +// http with { +// GET = "https://example.com" +// }; +// } +// } diff --git a/src/CsHttp/codegen.fsx b/src/CsHttp/codegen.fsx new file mode 100644 index 00000000..b11968e8 --- /dev/null +++ b/src/CsHttp/codegen.fsx @@ -0,0 +1,23 @@ +#r @"..\FsHttp\bin\Debug\net8.0\FsHttp.dll" + +open FsHttp +open System +open System.Reflection + +let allTypes = + let rec getNestedTypes (t: Type) = + [ + yield t + yield! t.GetNestedTypes() |> Seq.collect (fun t -> t :: (getNestedTypes t |> Seq.toList)) + ] + [ + for t in typedefof>.Assembly.GetTypes() do + yield! getNestedTypes t + ] + +for t in allTypes do + let members = t.GetMembers(BindingFlags.Public ||| BindingFlags.NonPublic ||| BindingFlags.Static) + for memb in members do + let cop = memb.GetCustomAttribute() + if cop :> obj <> null then + printfn $"Type = {t.FullName}, Member = {memb.Name}, Operation = {cop.Name}" diff --git a/src/FsHttp/Defaults.fs b/src/FsHttp/Defaults.fs index a4119c1b..d81f06b5 100644 --- a/src/FsHttp/Defaults.fs +++ b/src/FsHttp/Defaults.fs @@ -1,4 +1,4 @@ -module internal FsHttp.Defaults +module FsHttp.Defaults open System open System.Net