From 1ffe5ee3b035aecb828181ccb5f2d603eb64e4d1 Mon Sep 17 00:00:00 2001 From: SchlenkR Date: Sun, 24 Dec 2023 11:51:36 +0100 Subject: [PATCH] format --- src/FsHttp/Dsl.CE.fs | 132 ++++++++++++++++++++++++++++--------------- src/FsHttp/Dsl.fs | 99 +++++++++++++++++++++----------- 2 files changed, 154 insertions(+), 77 deletions(-) diff --git a/src/FsHttp/Dsl.CE.fs b/src/FsHttp/Dsl.CE.fs index 3ebc724a..9d13194f 100644 --- a/src/FsHttp/Dsl.CE.fs +++ b/src/FsHttp/Dsl.CE.fs @@ -37,37 +37,45 @@ let http = { config = None } type IRequestContext<'self> with [] - member this.Method(_: IRequestContext, method, url) = Http.method method url + member this.Method(_: IRequestContext, method, url) = + Http.method method url // RFC 2626 specifies 8 methods [] - member this.Get(context: IRequestContext, url) = getWithConfig context.Self.ActualConfig url + member this.Get(context: IRequestContext, url) = + getWithConfig context.Self.ActualConfig url [] - member this.Put(context: IRequestContext, url) = putWithConfig context.Self.ActualConfig url + member this.Put(context: IRequestContext, url) = + putWithConfig context.Self.ActualConfig url [] - member this.Post(context: IRequestContext, url) = postWithConfig context.Self.ActualConfig url + member this.Post(context: IRequestContext, url) = + postWithConfig context.Self.ActualConfig url [] - member this.Delete(context: IRequestContext, url) = deleteWithConfig context.Self.ActualConfig url + member this.Delete(context: IRequestContext, url) = + deleteWithConfig context.Self.ActualConfig url [] member this.Options(context: IRequestContext, url) = optionsWithConfig context.Self.ActualConfig url [] - member this.Head(context: IRequestContext, url) = headWithConfig context.Self.ActualConfig url + member this.Head(context: IRequestContext, url) = + headWithConfig context.Self.ActualConfig url [] - member this.Trace(context: IRequestContext, url) = traceWithConfig context.Self.ActualConfig url + member this.Trace(context: IRequestContext, url) = + traceWithConfig context.Self.ActualConfig url [] member this.Connect(context: IRequestContext, url) = connectWithConfig context.Self.ActualConfig url [] - member this.Patch(context: IRequestContext, url) = patchWithConfig context.Self.ActualConfig url + member this.Patch(context: IRequestContext, url) = + patchWithConfig context.Self.ActualConfig url // --------- @@ -78,19 +86,23 @@ type IRequestContext<'self> with /// Append query params [] - member this.Query(context: IRequestContext, queryParams) = Header.query queryParams context.Self + member this.Query(context: IRequestContext, queryParams) = + Header.query queryParams context.Self /// Custom headers [] - member this.Headers(context: IRequestContext, headers) = Header.headers headers context.Self + member this.Headers(context: IRequestContext, headers) = + Header.headers headers context.Self /// Custom header [] - member this.Header(context: IRequestContext, key, value) = Header.header key value context.Self + member this.Header(context: IRequestContext, key, value) = + Header.header key value context.Self /// Content-Types that are acceptable for the response [] - member this.Accept(context: IRequestContext, contentType) = Header.accept contentType context.Self + member this.Accept(context: IRequestContext, contentType) = + Header.accept contentType context.Self /// Character sets that are acceptable [] @@ -139,7 +151,8 @@ type IRequestContext<'self> with /// An HTTP cookie previously sent by the server with 'Set-Cookie'. [] - member this.SetCookie(context: IRequestContext, name, value) = Header.cookie name value context.Self + member this.SetCookie(context: IRequestContext, name, value) = + Header.cookie name value context.Self /// An HTTP cookie previously sent by the server with 'Set-Cookie' with /// the subset of URIs on the origin server to which this Cookie applies. @@ -156,29 +169,35 @@ type IRequestContext<'self> with /// The date and time that the message was sent [] - member this.Date(context: IRequestContext, date) = Header.date date context.Self + member this.Date(context: IRequestContext, date) = + Header.date date context.Self /// Indicates that particular server behaviors are required by the client [] - member this.Expect(context: IRequestContext, behaviors) = Header.expect behaviors context.Self + member this.Expect(context: IRequestContext, behaviors) = + Header.expect behaviors context.Self /// Gives the date/time after which the response is considered stale [] - member this.Expires(context: IRequestContext, dateTime) = Header.expires dateTime context.Self + member this.Expires(context: IRequestContext, dateTime) = + Header.expires dateTime context.Self /// The email address of the user making the request [] - member this.From(context: IRequestContext, email) = Header.from email context.Self + member this.From(context: IRequestContext, email) = + Header.from email context.Self /// The domain name of the server (for virtual hosting), and the TCP port number on which the server is listening. /// The port number may be omitted if the port is the standard port for the service requested. [] - member this.Host(context: IRequestContext, host) = Header.host host context.Self + member this.Host(context: IRequestContext, host) = + Header.host host context.Self /// Only perform the action if the client supplied entity matches the same entity on the server. /// This is mainly for methods like PUT to only update a resource if it has not been modified since the user last updated it. If-Match: "737060cd8c284d8af7ad3082f209582d" Permanent [] - member this.IfMatch(context: IRequestContext, entity) = Header.ifMatch entity context.Self + member this.IfMatch(context: IRequestContext, entity) = + Header.ifMatch entity context.Self /// Allows a 304 Not Modified to be returned if content is unchanged [] @@ -187,11 +206,13 @@ type IRequestContext<'self> with /// Allows a 304 Not Modified to be returned if content is unchanged [] - member this.IfNoneMatch(context: IRequestContext, etag) = Header.ifNoneMatch etag context.Self + member this.IfNoneMatch(context: IRequestContext, etag) = + Header.ifNoneMatch etag context.Self /// If the entity is unchanged, send me the part(s) that I am missing; otherwise, send me the entire new entity [] - member this.IfRange(context: IRequestContext, range) = Header.ifRange range context.Self + member this.IfRange(context: IRequestContext, range) = + Header.ifRange range context.Self /// Only send the response if the entity has not been modified since a specific time [] @@ -200,7 +221,8 @@ type IRequestContext<'self> with /// Specifies a parameter used into order to maintain a persistent connection [] - member this.KeepAlive(context: IRequestContext, keepAlive) = Header.keepAlive keepAlive context.Self + member this.KeepAlive(context: IRequestContext, keepAlive) = + Header.keepAlive keepAlive context.Self /// Specifies the date and time at which the accompanying body data was last modified [] @@ -209,19 +231,23 @@ type IRequestContext<'self> with /// Limit the number of times the message can be forwarded through proxies or gateways [] - member this.MaxForwards(context: IRequestContext, count) = Header.maxForwards count context.Self + member this.MaxForwards(context: IRequestContext, count) = + Header.maxForwards count context.Self /// Initiates a request for cross-origin resource sharing (asks server for an 'Access-Control-Allow-Origin' response header) [] - member this.Origin(context: IRequestContext, origin) = Header.origin origin context.Self + member this.Origin(context: IRequestContext, origin) = + Header.origin origin context.Self /// Implementation-specific headers that may have various effects anywhere along the request-response chain. [] - member this.Pragma(context: IRequestContext, pragma) = Header.pragma pragma context.Self + member this.Pragma(context: IRequestContext, pragma) = + Header.pragma pragma context.Self /// Optional instructions to the server to control request processing. See RFC https://tools.ietf.org/html/rfc7240 for more details [] - member this.Prefer(context: IRequestContext, prefer) = Header.prefer prefer context.Self + member this.Prefer(context: IRequestContext, prefer) = + Header.prefer prefer context.Self /// Authorization credentials for connecting to a proxy. [] @@ -230,22 +256,26 @@ type IRequestContext<'self> with /// Request only part of an entity. Bytes are numbered from 0 [] - member this.Range(context: IRequestContext, start, finish) = Header.range start finish context.Self + member this.Range(context: IRequestContext, start, finish) = + Header.range start finish context.Self /// This is the address of the previous web page from which a link to the currently requested page was followed. /// (The word "referrer" is misspelled in the RFC as well as in most implementations.) [] - member this.Referer(context: IRequestContext, referer) = Header.referer referer context.Self + member this.Referer(context: IRequestContext, referer) = + Header.referer referer context.Self /// The transfer encodings the user agent is willing to accept: the same values as for the response header /// Transfer-Encoding can be used, plus the "trailers" value (related to the "chunked" transfer method) to /// notify the server it expects to receive additional headers (the trailers) after the last, zero-sized, chunk. [] - member this.TE(context: IRequestContext, te) = Header.te te context.Self + member this.TE(context: IRequestContext, te) = + Header.te te context.Self /// The Trailer general field value indicates that the given set of header fields is present in the trailer of a message encoded with chunked transfer-coding [] - member this.Trailer(context: IRequestContext, trailer) = Header.trailer trailer context.Self + member this.Trailer(context: IRequestContext, trailer) = + Header.trailer trailer context.Self /// The TransferEncoding header indicates the form of encoding used to safely transfer the entity to the user. /// The valid directives are one of: chunked, compress, deflate, gzip, orentity. @@ -255,23 +285,28 @@ type IRequestContext<'self> with /// Microsoft extension to the HTTP specification used in conjunction with WebDAV functionality. [] - member this.Translate(context: IRequestContext, translate) = Header.translate translate context.Self + member this.Translate(context: IRequestContext, translate) = + Header.translate translate context.Self /// Specifies additional communications protocols that the client supports. [] - member this.Upgrade(context: IRequestContext, upgrade) = Header.upgrade upgrade context.Self + member this.Upgrade(context: IRequestContext, upgrade) = + Header.upgrade upgrade context.Self /// The user agent string of the user agent [] - member this.UserAgent(context: IRequestContext, userAgent) = Header.userAgent userAgent context.Self + member this.UserAgent(context: IRequestContext, userAgent) = + Header.userAgent userAgent context.Self /// Informs the server of proxies through which the request was sent [] - member this.Via(context: IRequestContext, server) = Header.via server context.Self + member this.Via(context: IRequestContext, server) = + Header.via server context.Self /// A general warning about possible problems with the entity body [] - member this.Warning(context: IRequestContext, message) = Header.warning message context.Self + member this.Warning(context: IRequestContext, message) = + Header.warning message context.Self /// Override HTTP method. [] @@ -287,23 +322,28 @@ type IRequestContext<'self> with /// An explicit transformation from a previous context to allow for describing the request body. [] - member this.Body(context: IRequestContext<#IToBodyContext>) = context.Self.Transform() + member this.Body(context: IRequestContext<#IToBodyContext>) = + context.Self.Transform() [] member this.Content(context: IRequestContext, contentType, data) = Body.content contentType data context.Self [] - member this.Binary(context: IRequestContext, data) = Body.binary data context.Self + member this.Binary(context: IRequestContext, data) = + Body.binary data context.Self [] - member this.Stream(context: IRequestContext, stream) = Body.stream stream context.Self + member this.Stream(context: IRequestContext, stream) = + Body.stream stream context.Self [] - member this.Text(context: IRequestContext, text) = Body.text text context.Self + member this.Text(context: IRequestContext, text) = + Body.text text context.Self [] - member this.Json(context: IRequestContext, json) = Body.json json context.Self + member this.Json(context: IRequestContext, json) = + Body.json json context.Self [] member this.JsonSerializeWith(context: IRequestContext, options, instance) = @@ -314,10 +354,12 @@ type IRequestContext<'self> with Body.jsonSerialize instance context.Self [] - member this.FormUrlEncoded(context: IRequestContext, data) = Body.formUrlEncoded data context.Self + member this.FormUrlEncoded(context: IRequestContext, data) = + Body.formUrlEncoded data context.Self [] - member this.File(context: IRequestContext, path) = Body.file path context.Self + member this.File(context: IRequestContext, path) = + Body.file path context.Self /// The type of encoding used on the data [] @@ -350,7 +392,8 @@ type IRequestContext<'self> with /// An explicit transformation from a previous context to allow for describing the request multiparts. [] - member this.Multipart(context: IRequestContext<#IToMultipartContext>) = context.Self.Transform() + member this.Multipart(context: IRequestContext<#IToMultipartContext>) = + context.Self.Transform() [] member this.TextPart(context: IRequestContext<#IToMultipartContext>, value, name, ?fileName) = @@ -413,7 +456,8 @@ type IRequestContext<'self> with Config.transformHttpClientHandler transformer context.Self [] - member this.Proxy(context: IRequestContext<#IConfigure>, url) = Config.proxy url context.Self + member this.Proxy(context: IRequestContext<#IConfigure>, url) = + Config.proxy url context.Self [] member this.ProxyWithCredentials(context: IRequestContext<#IConfigure>, url, credentials) = diff --git a/src/FsHttp/Dsl.fs b/src/FsHttp/Dsl.fs index 7e9bce7a..f383ac7a 100644 --- a/src/FsHttp/Dsl.fs +++ b/src/FsHttp/Dsl.fs @@ -84,23 +84,28 @@ module Header = } /// Content-Types that are acceptable for the response - let accept (contentType: string) (context: HeaderContext) = header "Accept" contentType context + let accept (contentType: string) (context: HeaderContext) = + header "Accept" contentType context /// Character sets that are acceptable - let acceptCharset (characterSets: string) (context: HeaderContext) = header "Accept-Charset" characterSets context + let acceptCharset (characterSets: string) (context: HeaderContext) = + header "Accept-Charset" characterSets context /// Acceptable version in time let acceptDatetime (dateTime: DateTime) (context: HeaderContext) = header "Accept-Datetime" (dateTime.ToString("R", CultureInfo.InvariantCulture)) context /// List of acceptable encodings. See HTTP compression. - let acceptEncoding (encoding: string) (context: HeaderContext) = header "Accept-Encoding" encoding context + let acceptEncoding (encoding: string) (context: HeaderContext) = + header "Accept-Encoding" encoding context /// List of acceptable human languages for response - let acceptLanguage (language: string) (context: HeaderContext) = header "Accept-Language" language context + let acceptLanguage (language: string) (context: HeaderContext) = + header "Accept-Language" language context /// Authorization credentials for HTTP authorization - let authorization (credentials: string) (context: HeaderContext) = header "Authorization" credentials context + let authorization (credentials: string) (context: HeaderContext) = + header "Authorization" credentials context /// Authorization header using Bearer authorization token let authorizationBearer (token: string) (context: HeaderContext) = @@ -113,10 +118,12 @@ module Header = authorization s context /// Used to specify directives that MUST be obeyed by all caching mechanisms along the request/response chain - let cacheControl (control: string) (context: HeaderContext) = header "Cache-Control" control context + let cacheControl (control: string) (context: HeaderContext) = + header "Cache-Control" control context /// What type of connection the user-agent would prefer - let connection (connection: string) (context: HeaderContext) = header "Connection" connection context + let connection (connection: string) (context: HeaderContext) = + header "Connection" connection context let private cookieDotnet (cookie: Cookie) (context: HeaderContext) = { context with @@ -124,7 +131,8 @@ module Header = } /// An HTTP cookie previously sent by the server with 'Set-Cookie'. - let cookie (name: string) (value: string) (context: HeaderContext) = cookieDotnet (Cookie(name, value)) context + let cookie (name: string) (value: string) (context: HeaderContext) = + cookieDotnet (Cookie(name, value)) context /// An HTTP cookie previously sent by the server with 'Set-Cookie' with /// the subset of URIs on the origin server to which this Cookie applies. @@ -142,7 +150,8 @@ module Header = header "Date" (date.ToString("R", CultureInfo.InvariantCulture)) context /// Indicates that particular server behaviors are required by the client - let expect (behaviors: string) (context: HeaderContext) = header "Expect" behaviors context + let expect (behaviors: string) (context: HeaderContext) = + header "Expect" behaviors context /// Gives the date/time after which the response is considered stale let expires (dateTime: DateTime) (context: HeaderContext) = @@ -151,48 +160,58 @@ module Header = // TODO: Forwarded ? /// The email address of the user making the request - let from (email: string) (context: HeaderContext) = header "From" email context + let from (email: string) (context: HeaderContext) = + header "From" email context /// The domain name of the server (for virtual hosting), and the TCP port number on which the server is listening. /// The port number may be omitted if the port is the standard port for the service requested. - let host (host: string) (context: HeaderContext) = header "Host" host context + let host (host: string) (context: HeaderContext) = + header "Host" host context /// Only perform the action if the client supplied entity matches the same entity on the server. /// This is mainly for methods like PUT to only update a resource if it has not been modified since the user last updated it. If-Match: "737060cd8c284d8af7ad3082f209582d" Permanent - let ifMatch (entity: string) (context: HeaderContext) = header "If-Match" entity context + let ifMatch (entity: string) (context: HeaderContext) = + header "If-Match" entity context /// Allows a 304 Not Modified to be returned if content is unchanged let ifModifiedSince (dateTime: DateTime) (context: HeaderContext) = header "If-Modified-Since" (dateTime.ToString("R", CultureInfo.InvariantCulture)) context /// Allows a 304 Not Modified to be returned if content is unchanged - let ifNoneMatch (etag: string) (context: HeaderContext) = header "If-None-Match" etag context + let ifNoneMatch (etag: string) (context: HeaderContext) = + header "If-None-Match" etag context /// If the entity is unchanged, send me the part(s) that I am missing; otherwise, send me the entire new entity - let ifRange (range: string) (context: HeaderContext) = header "If-Range" range context + let ifRange (range: string) (context: HeaderContext) = + header "If-Range" range context /// Only send the response if the entity has not been modified since a specific time let ifUnmodifiedSince (dateTime: DateTime) (context: HeaderContext) = header "If-Unmodified-Since" (dateTime.ToString("R", CultureInfo.InvariantCulture)) context /// Specifies a parameter used into order to maintain a persistent connection - let keepAlive (keepAlive: string) (context: HeaderContext) = header "Keep-Alive" keepAlive context + let keepAlive (keepAlive: string) (context: HeaderContext) = + header "Keep-Alive" keepAlive context /// Specifies the date and time at which the accompanying body data was last modified let lastModified (dateTime: DateTime) (context: HeaderContext) = header "Last-Modified" (dateTime.ToString("R", CultureInfo.InvariantCulture)) context /// Limit the number of times the message can be forwarded through proxies or gateways - let maxForwards (count: int) (context: HeaderContext) = header "Max-Forwards" (count.ToString()) context + let maxForwards (count: int) (context: HeaderContext) = + header "Max-Forwards" (count.ToString()) context /// Initiates a request for cross-origin resource sharing (asks server for an 'Access-Control-Allow-Origin' response header) - let origin (origin: string) (context: HeaderContext) = header "Origin" origin context + let origin (origin: string) (context: HeaderContext) = + header "Origin" origin context /// Implementation-specific headers that may have various effects anywhere along the request-response chain. - let pragma (pragma: string) (context: HeaderContext) = header "Pragma" pragma context + let pragma (pragma: string) (context: HeaderContext) = + header "Pragma" pragma context /// Optional instructions to the server to control request processing. See RFC https://tools.ietf.org/html/rfc7240 for more details - let prefer (prefer: string) (context: HeaderContext) = header "Prefer" prefer context + let prefer (prefer: string) (context: HeaderContext) = + header "Prefer" prefer context /// Authorization credentials for connecting to a proxy. let proxyAuthorization (credentials: string) (context: HeaderContext) = @@ -203,33 +222,42 @@ module Header = header "Range" (sprintf "bytes=%d-%d" start finish) context /// This is the address of the previous web page from which a link to the currently requested page was followed. (The word "referrer" is misspelled in the RFC as well as in most implementations.) - let referer (referer: string) (context: HeaderContext) = header "Referer" referer context + let referer (referer: string) (context: HeaderContext) = + header "Referer" referer context /// The transfer encodings the user agent is willing to accept: the same values as for the response header /// Transfer-Encoding can be used, plus the "trailers" value (related to the "chunked" transfer method) to /// notify the server it expects to receive additional headers (the trailers) after the last, zero-sized, chunk. - let te (te: string) (context: HeaderContext) = header "TE" te context + let te (te: string) (context: HeaderContext) = + header "TE" te context /// The Trailer general field value indicates that the given set of header fields is present in the trailer of a message encoded with chunked transfer-coding - let trailer (trailer: string) (context: HeaderContext) = header "Trailer" trailer context + let trailer (trailer: string) (context: HeaderContext) = + header "Trailer" trailer context /// The TransferEncoding header indicates the form of encoding used to safely transfer the entity to the user. The valid directives are one of: chunked, compress, deflate, gzip, or identity. - let transferEncoding (directive: string) (context: HeaderContext) = header "Transfer-Encoding" directive context + let transferEncoding (directive: string) (context: HeaderContext) = + header "Transfer-Encoding" directive context /// Microsoft extension to the HTTP specification used in conjunction with WebDAV functionality. - let translate (translate: string) (context: HeaderContext) = header "Translate" translate context + let translate (translate: string) (context: HeaderContext) = + header "Translate" translate context /// Specifies additional communications protocols that the client supports. - let upgrade (upgrade: string) (context: HeaderContext) = header "Upgrade" upgrade context + let upgrade (upgrade: string) (context: HeaderContext) = + header "Upgrade" upgrade context /// The user agent string of the user agent - let userAgent (userAgent: string) (context: HeaderContext) = header "User-Agent" userAgent context + let userAgent (userAgent: string) (context: HeaderContext) = + header "User-Agent" userAgent context /// Informs the server of proxies through which the request was sent - let via (server: string) (context: HeaderContext) = header "Via" server context + let via (server: string) (context: HeaderContext) = + header "Via" server context /// A general warning about possible problems with the entity body - let warning (message: string) (context: HeaderContext) = header "Warning" message context + let warning (message: string) (context: HeaderContext) = + header "Warning" message context /// Override HTTP method. let xhttpMethodOverride (httpMethod: string) (context: HeaderContext) = @@ -249,7 +277,8 @@ module Body = } /// The type of encoding used on the data - let contentEncoding (encoding: string) (context: IToBodyContext) = header "Content-Encoding" encoding context + let contentEncoding (encoding: string) (context: IToBodyContext) = + header "Content-Encoding" encoding context /// 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) = @@ -274,16 +303,20 @@ module Body = // b) the others are response fields /// The language the content is in - let contentLanguage (language: string) (context: IToBodyContext) = header "Content-Language" language context + let contentLanguage (language: string) (context: IToBodyContext) = + header "Content-Language" language context /// An alternate location for the returned data - let contentLocation (location: string) (context: IToBodyContext) = header "Content-Location" location context + let contentLocation (location: string) (context: IToBodyContext) = + header "Content-Location" location context /// A Base64-encoded binary MD5 sum of the content of the request body - let contentMD5 (md5sum: string) (context: IToBodyContext) = header "Content-MD5" md5sum context + let contentMD5 (md5sum: string) (context: IToBodyContext) = + header "Content-MD5" md5sum context /// Where in a full body message this partial message belongs - let contentRange (range: string) (context: IToBodyContext) = header "Content-Range" range context + let contentRange (range: string) (context: IToBodyContext) = + header "Content-Range" range context let content defaultContentType (data: ContentData) (context: IToBodyContext) = let context = context.Transform()