[swift-server-dev] HTTP API v0.1.0

Helge Heß me at helgehess.eu
Tue Nov 7 06:46:36 CST 2017


On 6. Nov 2017, at 19:52, Helge Heß via swift-server-dev <swift-server-dev at swift.org> wrote:
> On 6. Nov 2017, at 19:20, Johannes Weiß <johannesweiss at apple.com> wrote:
>> 
>> Hi Helge,
>> 
>> Why not a
>> 
>> protocol HTTPRequestHandling {
>>   associatedtype Context
>> }
>> 
>> then an implementation that uses DispatchQueues can make `typealias Context = DispatchQueue` or whatever it feels like?
> 
> I’m not entirely sure I can follow you here. IMO the `HTTPRequestHandling` protocol doesn’t belong here. It can be useful for OO oriented APIs, but it provided zero value to this framework.
> 
> So the primary handler type would be a closure:
> 
>  (HTTPRequest, HTTPResponseWriter, SyncContext)
> 
> And I can’t make the SyncContext generic in this, right?

Thinking about this, we could make the whole server class generic and do something like Apache MPM to select synchronous/async MPMs.

Like so:

  let server = HTTPServer<SyncSocketMPM>(port: 0xF00)

and

  let server = HTTPServer<DispatchMPM>(port: 1337)

where we have

  protocol HTTPServerProcessingModule {
    associatedtype SyncContext
    associatedtype RequestHead
    associatedtype ResponseWriter
    associatedtype Configuration // like Apache Server MPM config
    typealias Handler = ( RequestHead, ResponseWriter, SyncContext )
  }

  class HTTPServer<MPM: HTTPProcessingModule> {

    init(port          : Int? = nil,
         handler       : MPM.Handler,
         configuration : MPM.Configuration? = nil)
    { ..}
  }

Maybe that is a overkill for this effort, but it may be a sweet way to switch implementations w/o dynamic overhead.


What do you think?

hh



More information about the swift-server-dev mailing list