Skip to content

Commit ab984c5

Browse files
committed
Add Support for Unix Sockets in ApplicationBuilder
Kestrel supports unix sockets. This change surfaces this support by introducing a new custom operation for specifying unix sockets to listen on.
1 parent 4ae4d61 commit ab984c5

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/Saturn/Application.fs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ module Application =
6363
ErrorHandler: ErrorHandler option
6464
Pipelines: HttpHandler list
6565
Urls: string list
66+
Sockets : string list
6667
MimeTypes: (string*string) list
6768
AppConfigs: (IApplicationBuilder -> IApplicationBuilder) list
6869
HostConfigs: (IHostBuilder -> IHostBuilder) list
@@ -104,6 +105,7 @@ module Application =
104105
/// pipe_through endpointPipe
105106
/// use_router topRouter
106107
/// url "http://0.0.0.0:8085/"
108+
/// socket "/tmp/socket"
107109
/// memory_cache
108110
/// use_static "static"
109111
/// use_gzip
@@ -114,7 +116,7 @@ module Application =
114116
let errorHandler (ex : Exception) (logger : ILogger) =
115117
logger.LogError(EventId(), ex, "An unhandled exception has occurred while executing the request.")
116118
clearResponse >=> Giraffe.HttpStatusCodeHandlers.ServerErrors.INTERNAL_ERROR ex.Message
117-
{Router = None; EndpointRouter = None; ErrorHandler = Some errorHandler; Pipelines = []; Urls = []; MimeTypes = []; AppConfigs = []; HostConfigs = []; ServicesConfig = []; WebHostConfigs = []; CliArguments = None; CookiesAlreadyAdded = false; NoRouter = false; NoWebhost = false; Channels = [] }
119+
{Router = None; EndpointRouter = None; ErrorHandler = Some errorHandler; Pipelines = []; Urls = []; Sockets = []; MimeTypes = []; AppConfigs = []; HostConfigs = []; ServicesConfig = []; WebHostConfigs = []; CliArguments = None; CookiesAlreadyAdded = false; NoRouter = false; NoWebhost = false; Channels = [] }
118120

119121
member __.Run(state: ApplicationState) : IHostBuilder =
120122
// to build the app we have to separate our configurations and our pipelines.
@@ -214,6 +216,12 @@ module Application =
214216
if not (state.Urls |> List.isEmpty) then
215217
wbhst.UseUrls(state.Urls |> List.toArray)
216218
else wbhst
219+
let wbhst =
220+
if not (state.Sockets |> List.isEmpty) then
221+
wbhst.ConfigureKestrel (fun options ->
222+
state.Sockets |> List.iter options.ListenUnixSocket
223+
)
224+
else wbhst
217225
let wbhst =
218226
wbhst.Configure(fun ab ->
219227
(ab, useParts)
@@ -279,6 +287,11 @@ module Application =
279287
member __.Url(state, url) =
280288
{state with Urls = url::state.Urls}
281289

290+
///Adds socket
291+
[<CustomOperation("socket")>]
292+
member __.Socket(state, socket) =
293+
{state with Sockets = socket::state.Sockets}
294+
282295
///Adds MIME types definitions as a list of (extension, mime)
283296
[<CustomOperation("use_mime_types")>]
284297
member __.AddMimeTypes(state, mimeList) =

0 commit comments

Comments
 (0)