Skip to content

Commit

Permalink
renamed internal things
Browse files Browse the repository at this point in the history
  • Loading branch information
SchlenkR committed Jan 3, 2024
1 parent 6d9d471 commit 782483a
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 77 deletions.
72 changes: 36 additions & 36 deletions src/FsHttp/Domain.fs
Original file line number Diff line number Diff line change
Expand Up @@ -114,28 +114,28 @@ type Request = {
}

type IToRequest =
abstract member Transform: unit -> Request
abstract member ToRequest: unit -> Request

type IConfigure<'t, 'self> =
abstract member Configure: 't -> 'self
type IUpdateConfig<'t, 'self> =
abstract member UpdateConfig: 't -> 'self

// It seems to impossible extending builder methods on the context type
// directly when they are not polymorph.
type IRequestContext<'self> =
abstract member Self: 'self

let configPrinter (c: IConfigure<ConfigTransformer, _>) transformPrintHint =
c.Configure(fun conf -> { conf with printHint = transformPrintHint conf.printHint })
let configPrinter (c: IUpdateConfig<ConfigTransformer, _>) transformPrintHint =
c.UpdateConfig(fun conf -> { conf with printHint = transformPrintHint conf.printHint })

// Unifying IToBodyContext and IToMultipartContext doesn't work; see:
// https://github.com/dotnet/fsharp/issues/12814
type IToBodyContext =
inherit IToRequest
abstract member Transform: unit -> BodyContext
abstract member ToBodyContext: unit -> BodyContext

and IToMultipartContext =
inherit IToRequest
abstract member Transform: unit -> MultipartContext
abstract member ToMultipartContext: unit -> MultipartContext

// TODO: Convert this to a class.
and HeaderContext = {
Expand All @@ -145,21 +145,21 @@ and HeaderContext = {
interface IRequestContext<HeaderContext> with
member this.Self = this

interface IConfigure<ConfigTransformer, HeaderContext> with
member this.Configure(transformConfig) = { this with config = transformConfig this.config }
interface IUpdateConfig<ConfigTransformer, HeaderContext> with
member this.UpdateConfig(transformConfig) = { this with config = transformConfig this.config }

interface IConfigure<PrintHintTransformer, HeaderContext> with
member this.Configure(transformPrintHint) = configPrinter this transformPrintHint
interface IUpdateConfig<PrintHintTransformer, HeaderContext> with
member this.UpdateConfig(transformPrintHint) = configPrinter this transformPrintHint

interface IToRequest with
member this.Transform() = {
member this.ToRequest() = {
header = this.header
content = Empty
config = this.config
}

interface IToBodyContext with
member this.Transform() = {
member this.ToBodyContext() = {
header = this.header
bodyContent = {
contentElement = {
Expand All @@ -172,7 +172,7 @@ and HeaderContext = {
}

interface IToMultipartContext with
member this.Transform() = {
member this.ToMultipartContext() = {
header = this.header
config = this.config
multipartContent = {
Expand All @@ -190,21 +190,21 @@ and BodyContext = {
interface IRequestContext<BodyContext> with
member this.Self = this

interface IConfigure<ConfigTransformer, BodyContext> with
member this.Configure(transformConfig) = { this with config = transformConfig this.config }
interface IUpdateConfig<ConfigTransformer, BodyContext> with
member this.UpdateConfig(transformConfig) = { this with config = transformConfig this.config }

interface IConfigure<PrintHintTransformer, BodyContext> with
member this.Configure(transformPrintHint) = configPrinter this transformPrintHint
interface IUpdateConfig<PrintHintTransformer, BodyContext> with
member this.UpdateConfig(transformPrintHint) = configPrinter this transformPrintHint

interface IToRequest with
member this.Transform() = {
member this.ToRequest() = {
header = this.header
content = Single this.bodyContent
config = this.config
}

interface IToBodyContext with
member this.Transform() = this
member this.ToBodyContext() = this

// TODO: Convert this to a class.
and MultipartContext = {
Expand All @@ -215,21 +215,21 @@ and MultipartContext = {
interface IRequestContext<MultipartContext> with
member this.Self = this

interface IConfigure<ConfigTransformer, MultipartContext> with
member this.Configure(transformConfig) = { this with config = transformConfig this.config }
interface IUpdateConfig<ConfigTransformer, MultipartContext> with
member this.UpdateConfig(transformConfig) = { this with config = transformConfig this.config }

interface IConfigure<PrintHintTransformer, MultipartContext> with
member this.Configure(transformPrintHint) = configPrinter this transformPrintHint
interface IUpdateConfig<PrintHintTransformer, MultipartContext> with
member this.UpdateConfig(transformPrintHint) = configPrinter this transformPrintHint

interface IToRequest with
member this.Transform() = {
member this.ToRequest() = {
header = this.header
content = Multi this.multipartContent
config = this.config
}

interface IToMultipartContext with
member this.Transform() = this
member this.ToMultipartContext() = this

// TODO: Convert this to a class.
and MultipartElementContext = {
Expand All @@ -240,21 +240,21 @@ and MultipartElementContext = {
interface IRequestContext<MultipartElementContext> with
member this.Self = this

interface IConfigure<ConfigTransformer, MultipartElementContext> with
member this.Configure(transformConfig) =
interface IUpdateConfig<ConfigTransformer, MultipartElementContext> with
member this.UpdateConfig(transformConfig) =
let updatedCfg = this.parent.config |> transformConfig
{ this with parent.config = updatedCfg }

interface IConfigure<PrintHintTransformer, MultipartElementContext> with
member this.Configure(transformPrintHint) = configPrinter this transformPrintHint
interface IUpdateConfig<PrintHintTransformer, MultipartElementContext> with
member this.UpdateConfig(transformPrintHint) = configPrinter this transformPrintHint

interface IToRequest with
member this.Transform() =
let parentWithSelf = (this :> IToMultipartContext).Transform()
(parentWithSelf :> IToRequest).Transform()
member this.ToRequest() =
let parentWithSelf = (this :> IToMultipartContext).ToMultipartContext()
(parentWithSelf :> IToRequest).ToRequest()

interface IToMultipartContext with
member this.Transform() =
member this.ToMultipartContext() =
let parentElementsAndSelf = this.parent.multipartContent.partElements @ [ this.part ]
{ this with parent.multipartContent.partElements = parentElementsAndSelf }.parent

Expand All @@ -270,8 +270,8 @@ type Response = {
originalHttpResponseMessage: System.Net.Http.HttpResponseMessage
dispose: unit -> unit
} with
interface IConfigure<PrintHintTransformer, Response> with
member this.Configure(transformPrintHint) =
interface IUpdateConfig<PrintHintTransformer, Response> with
member this.UpdateConfig(transformPrintHint) =
{ this with request.config.printHint = transformPrintHint this.request.config.printHint }

interface System.IDisposable with
Expand Down
52 changes: 26 additions & 26 deletions src/FsHttp/Dsl.CE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ type IRequestContext<'self> with
/// An explicit transformation from a previous context to allow for describing the request body.
[<CustomOperation("body")>]
member this.Body(context: IRequestContext<#IToBodyContext>) =
context.Self.Transform()
context.Self.ToBodyContext()

[<CustomOperation("content")>]
member this.Content(context: IRequestContext<BodyContext>, contentType, data) =
Expand Down Expand Up @@ -381,7 +381,7 @@ type IRequestContext<'self> with
/// An explicit transformation from a previous context to allow for describing the request multiparts.
[<CustomOperation("multipart")>]
member this.Multipart(context: IRequestContext<#IToMultipartContext>) =
context.Self.Transform()
context.Self.ToMultipartContext()

[<CustomOperation("textPart")>]
member this.TextPart(context: IRequestContext<#IToMultipartContext>, value, name, ?fileName) =
Expand All @@ -407,68 +407,68 @@ type IRequestContext<'self> with
type IRequestContext<'self> with

[<CustomOperation("config_update")>]
member this.Update(context: IRequestContext<#IConfigure<ConfigTransformer, _>>, configTransformer) =
member this.Update(context: IRequestContext<#IUpdateConfig<ConfigTransformer, _>>, configTransformer) =
Config.update configTransformer context.Self

[<CustomOperation("config_set")>]
member this.Set(context: IRequestContext<#IConfigure<ConfigTransformer, _>>, configTransformer) =
member this.Set(context: IRequestContext<#IUpdateConfig<ConfigTransformer, _>>, configTransformer) =
Config.set configTransformer context.Self

// TODO: Provide certStrategy configs
[<CustomOperation("config_ignoreCertIssues")>]
member this.IgnoreCertIssues(context: IRequestContext<#IConfigure<ConfigTransformer, _>>) =
member this.IgnoreCertIssues(context: IRequestContext<#IUpdateConfig<ConfigTransformer, _>>) =
Config.ignoreCertIssues context.Self

[<CustomOperation("config_timeout")>]
member this.Timeout(context: IRequestContext<#IConfigure<ConfigTransformer, _>>, value) =
member this.Timeout(context: IRequestContext<#IUpdateConfig<ConfigTransformer, _>>, value) =
Config.timeout value context.Self

[<CustomOperation("config_timeoutInSeconds")>]
member this.TimeoutInSeconds(context: IRequestContext<#IConfigure<ConfigTransformer, _>>, value) =
member this.TimeoutInSeconds(context: IRequestContext<#IUpdateConfig<ConfigTransformer, _>>, value) =
Config.timeoutInSeconds value context.Self

[<CustomOperation("config_transformHeader")>]
member this.TransformHeader(context: IRequestContext<#IConfigure<ConfigTransformer, _>>, transformer) =
member this.TransformHeader(context: IRequestContext<#IUpdateConfig<ConfigTransformer, _>>, transformer) =
Config.transformHeader transformer context.Self

[<CustomOperation("config_setHttpClientFactory")>]
member this.SetHttpClientFactory(context: IRequestContext<#IConfigure<ConfigTransformer, _>>, httpClientFactory) =
member this.SetHttpClientFactory(context: IRequestContext<#IUpdateConfig<ConfigTransformer, _>>, httpClientFactory) =
Config.setHttpClientFactory httpClientFactory context.Self

[<CustomOperation("config_transformHttpClient")>]
member this.TransformHttpClient(context: IRequestContext<#IConfigure<ConfigTransformer, _>>, transformer) =
member this.TransformHttpClient(context: IRequestContext<#IUpdateConfig<ConfigTransformer, _>>, transformer) =
Config.transformHttpClient transformer context.Self

[<CustomOperation("config_transformHttpRequestMessage")>]
member this.TransformHttpRequestMessage(context: IRequestContext<#IConfigure<ConfigTransformer, _>>, transformer) =
member this.TransformHttpRequestMessage(context: IRequestContext<#IUpdateConfig<ConfigTransformer, _>>, transformer) =
Config.transformHttpRequestMessage transformer context.Self

[<CustomOperation("config_transformHttpClientHandler")>]
member this.TransformHttpClientHandler(context: IRequestContext<#IConfigure<ConfigTransformer, _>>, transformer) =
member this.TransformHttpClientHandler(context: IRequestContext<#IUpdateConfig<ConfigTransformer, _>>, transformer) =
Config.transformHttpClientHandler transformer context.Self

[<CustomOperation("config_proxy")>]
member this.Proxy(context: IRequestContext<#IConfigure<ConfigTransformer, _>>, url) =
member this.Proxy(context: IRequestContext<#IUpdateConfig<ConfigTransformer, _>>, url) =
Config.proxy url context.Self

[<CustomOperation("config_proxyWithCredentials")>]
member this.ProxyWithCredentials(context: IRequestContext<#IConfigure<ConfigTransformer, _>>, url, credentials) =
member this.ProxyWithCredentials(context: IRequestContext<#IUpdateConfig<ConfigTransformer, _>>, url, credentials) =
Config.proxyWithCredentials url credentials context.Self

[<CustomOperation("config_decompressionMethods")>]
member this.DecompressionMethods
(
context: IRequestContext<#IConfigure<ConfigTransformer, _>>,
context: IRequestContext<#IUpdateConfig<ConfigTransformer, _>>,
decompressionMethods
) =
Config.decompressionMethods decompressionMethods context.Self

[<CustomOperation("config_noDecompression")>]
member this.NoDecompression(context: IRequestContext<#IConfigure<ConfigTransformer, _>>) =
member this.NoDecompression(context: IRequestContext<#IUpdateConfig<ConfigTransformer, _>>) =
Config.noDecompression context.Self

[<CustomOperation("config_cancellationToken")>]
member this.CancellationToken(context: IRequestContext<#IConfigure<ConfigTransformer, _>>, cancellationToken) =
member this.CancellationToken(context: IRequestContext<#IUpdateConfig<ConfigTransformer, _>>, cancellationToken) =
Config.cancellationToken cancellationToken context.Self


Expand All @@ -479,37 +479,37 @@ type IRequestContext<'self> with
type IRequestContext<'self> with

[<CustomOperation("print_withConfig")>]
member this.WithConfig(context: IRequestContext<#IConfigure<PrintHintTransformer, _>>, updatePrintHint) =
member this.WithConfig(context: IRequestContext<#IUpdateConfig<PrintHintTransformer, _>>, updatePrintHint) =
Print.withConfig updatePrintHint context.Self

[<CustomOperation("print_withRequestPrintMode")>]
member this.WithRequestPrintMode(context: IRequestContext<#IConfigure<PrintHintTransformer, _>>, updatePrintMode) =
member this.WithRequestPrintMode(context: IRequestContext<#IUpdateConfig<PrintHintTransformer, _>>, updatePrintMode) =
Print.withRequestPrintMode updatePrintMode context.Self

[<CustomOperation("print_withResponsePrintMode")>]
member this.WithResponsePrintMode(context: IRequestContext<#IConfigure<PrintHintTransformer, _>>, updatePrintMode) =
member this.WithResponsePrintMode(context: IRequestContext<#IUpdateConfig<PrintHintTransformer, _>>, updatePrintMode) =
Print.withResponsePrintMode updatePrintMode context.Self

[<CustomOperation("print_withResponseBody")>]
member this.WithResponseBody(context: IRequestContext<#IConfigure<PrintHintTransformer, _>>, updateBodyPrintMode) =
member this.WithResponseBody(context: IRequestContext<#IUpdateConfig<PrintHintTransformer, _>>, updateBodyPrintMode) =
Print.withResponseBody updateBodyPrintMode context.Self

[<CustomOperation("print_useObjectFormatting")>]
member this.UseObjectFormatting(context: IRequestContext<#IConfigure<PrintHintTransformer, _>>) =
member this.UseObjectFormatting(context: IRequestContext<#IUpdateConfig<PrintHintTransformer, _>>) =
Print.useObjectFormatting context.Self

[<CustomOperation("print_headerOnly")>]
member this.HeaderOnly(context: IRequestContext<#IConfigure<PrintHintTransformer, _>>) =
member this.HeaderOnly(context: IRequestContext<#IUpdateConfig<PrintHintTransformer, _>>) =
Print.headerOnly context.Self

[<CustomOperation("print_withResponseBodyLength")>]
member this.WithResponseBodyLength(context: IRequestContext<#IConfigure<PrintHintTransformer, _>>, maxLength) =
member this.WithResponseBodyLength(context: IRequestContext<#IUpdateConfig<PrintHintTransformer, _>>, maxLength) =
Print.withResponseBodyLength maxLength context.Self

[<CustomOperation("print_withResponseBodyFormat")>]
member this.WithResponseBodyFormat(context: IRequestContext<#IConfigure<PrintHintTransformer, _>>, format) =
member this.WithResponseBodyFormat(context: IRequestContext<#IUpdateConfig<PrintHintTransformer, _>>, format) =
Print.withResponseBodyFormat format context.Self

[<CustomOperation("print_withResponseBodyExpanded")>]
member this.WithResponseBodyExpanded(context: IRequestContext<#IConfigure<PrintHintTransformer, _>>) =
member this.WithResponseBodyExpanded(context: IRequestContext<#IUpdateConfig<PrintHintTransformer, _>>) =
Print.withResponseBodyExpanded context.Self
16 changes: 8 additions & 8 deletions src/FsHttp/Dsl.fs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ module Body =

/// Adds a header
let header name value (context: IToBodyContext) =
let context = context.Transform()
let context = context.ToBodyContext()
{ context with bodyContent.headers = Map.union context.header.headers [ name, value ] }

/// The type of encoding used on the data
Expand All @@ -293,7 +293,7 @@ module Body =

/// The MIME type of the body of the request (used with POST and PUT requests) with an optional encoding
let contentType (contentType: string) (charset: Encoding option) (context: IToBodyContext) =
let context = context.Transform()
let context = context.ToBodyContext()
{ context with bodyContent.contentElement.explicitContentType = Some { value = contentType; charset = charset } }

// a) MD5 is obsolete. See https://tools.ietf.org/html/rfc7231#appendix-B
Expand All @@ -316,7 +316,7 @@ module Body =
header "Content-Range" range context

let content defaultContentType (data: ContentData) (context: IToBodyContext) =
let context = context.Transform()
let context = context.ToBodyContext()
let contentType =
context.bodyContent.contentElement.explicitContentType
|> Option.defaultValue defaultContentType
Expand Down Expand Up @@ -408,7 +408,7 @@ module MultipartElement =
module Multipart =

let private part (content: ContentData) (name: string) (fileName: string option) (context: IToMultipartContext) =
let context = context.Transform()
let context = context.ToMultipartContext()

let multipartElement = {
MultipartElement.name = name
Expand Down Expand Up @@ -491,8 +491,8 @@ module Config =
let cancellationToken cancellationToken config =
{ config with cancellationToken = cancellationToken }

let update transformer (context: IConfigure<ConfigTransformer, _>) =
context.Configure transformer
let update transformer (context: IUpdateConfig<ConfigTransformer, _>) =
context.UpdateConfig transformer

let set (config: Config) context =
context |> update (fun _ -> config)
Expand Down Expand Up @@ -539,8 +539,8 @@ module Config =

module Print =

let withConfig transformer (context: IConfigure<PrintHintTransformer, _>) =
context.Configure transformer
let withConfig transformer (context: IUpdateConfig<PrintHintTransformer, _>) =
context.UpdateConfig transformer

let withRequestPrintMode updatePrintMode context =
context |> withConfig (fun printHint ->
Expand Down
4 changes: 2 additions & 2 deletions src/FsHttp/Extensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ type BodyExtensions =
/// An explicit transformation from a previous context to allow for describing the request body.
[<Extension>]
static member Body(context: IRequestContext<#IToBodyContext>) =
context.Self.Transform()
context.Self.ToBodyContext()

[<Extension>]
static member Content(context: IRequestContext<BodyContext>, contentType, data) =
Expand Down Expand Up @@ -385,7 +385,7 @@ type MultipartExtensions =
/// An explicit transformation from a previous context to allow for describing the request multiparts.
[<Extension>]
static member Multipart(context: IRequestContext<#IToMultipartContext>) =
context.Self.Transform()
context.Self.ToMultipartContext()

[<Extension>]
static member TextPart(context: IRequestContext<MultipartContext>, value, name, ?fileName) =
Expand Down
Loading

0 comments on commit 782483a

Please sign in to comment.