-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved all defaults to Defaults module
- Loading branch information
Showing
11 changed files
with
154 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
module internal FsHttp.Defaults | ||
|
||
open System | ||
open System.Net | ||
open System.Net.Http | ||
|
||
open FsHttp | ||
open System.Text.Json | ||
|
||
let defaultJsonDocumentOptions = JsonDocumentOptions() | ||
let defaultJsonSerializerOptions = JsonSerializerOptions JsonSerializerDefaults.Web | ||
|
||
let defaultHttpClientFactory (config: Config) = | ||
let getDefaultSslHandler ignoreSslIssues = | ||
#if NETSTANDARD2_0 || NETSTANDARD2_1 | ||
let handler = new HttpClientHandler() | ||
|
||
if ignoreSslIssues then | ||
handler.ServerCertificateCustomValidationCallback <- (fun msg cert chain errors -> true) | ||
|
||
handler | ||
#else | ||
let handler = | ||
new SocketsHttpHandler(UseCookies = false, PooledConnectionLifetime = TimeSpan.FromMinutes 5.0) | ||
|
||
if ignoreSslIssues then | ||
handler.SslOptions <- | ||
let options = Security.SslClientAuthenticationOptions() | ||
|
||
let callback = | ||
Security.RemoteCertificateValidationCallback(fun sender cert chain errors -> true) | ||
|
||
do options.RemoteCertificateValidationCallback <- callback | ||
options | ||
|
||
handler | ||
#endif | ||
|
||
let ignoreSslIssues = | ||
match config.certErrorStrategy with | ||
| Default -> false | ||
| AlwaysAccept -> true | ||
|
||
let handler = | ||
let initHandler = getDefaultSslHandler ignoreSslIssues | ||
config.httpClientHandlerTransformers |> List.fold (fun c n -> n c) initHandler | ||
|
||
match config.proxy with | ||
| Some proxy -> | ||
let webProxy = WebProxy(proxy.url) | ||
|
||
match proxy.credentials with | ||
| Some cred -> | ||
webProxy.UseDefaultCredentials <- false | ||
webProxy.Credentials <- cred | ||
| None -> webProxy.UseDefaultCredentials <- true | ||
|
||
handler.Proxy <- webProxy | ||
| None -> () | ||
|
||
let client = new HttpClient(handler) | ||
do config.timeout |> Option.iter (fun timeout -> client.Timeout <- timeout) | ||
client | ||
|
||
let defaultHeadersAndBodyPrintMode = { | ||
format = true | ||
maxLength = Some 7000 | ||
} | ||
|
||
let defaultConfig = { | ||
timeout = None | ||
printHint = { | ||
requestPrintMode = HeadersAndBody(defaultHeadersAndBodyPrintMode) | ||
responsePrintMode = HeadersAndBody(defaultHeadersAndBodyPrintMode) | ||
} | ||
httpMessageTransformers = [] | ||
httpClientHandlerTransformers = [] | ||
httpClientTransformers = [] | ||
httpClientFactory = defaultHttpClientFactory | ||
httpCompletionOption = HttpCompletionOption.ResponseHeadersRead | ||
proxy = None | ||
certErrorStrategy = Default | ||
bufferResponseContent = false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.