mirror of
https://github.com/caddyserver/caddy.git
synced 2026-01-17 01:30:34 +00:00
Implement config adapters and beginning of Caddyfile adapter
Along with several other changes, such as renaming caddyhttp.ServerRoute to caddyhttp.Route, exporting some types that were not exported before, and tweaking the caddytls TLS values to be more consistent. Notably, we also now disable automatic cert management for names which already have a cert (manually) loaded into the cache. These names no longer need to be specified in the "skip_certificates" field of the automatic HTTPS config, because they will be skipped automatically.
This commit is contained in:
@@ -52,19 +52,15 @@ type Encode struct {
|
||||
|
||||
// Provision provisions enc.
|
||||
func (enc *Encode) Provision(ctx caddy.Context) error {
|
||||
enc.writerPools = make(map[string]*sync.Pool)
|
||||
|
||||
for modName, rawMsg := range enc.EncodingsRaw {
|
||||
val, err := ctx.LoadModule("http.encoders."+modName, rawMsg)
|
||||
if err != nil {
|
||||
return fmt.Errorf("loading encoder module '%s': %v", modName, err)
|
||||
}
|
||||
encoder := val.(Encoding)
|
||||
|
||||
enc.writerPools[encoder.AcceptEncoding()] = &sync.Pool{
|
||||
New: func() interface{} {
|
||||
return encoder.NewEncoder()
|
||||
},
|
||||
encoding := val.(Encoding)
|
||||
err = enc.addEncoding(encoding)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
enc.EncodingsRaw = nil // allow GC to deallocate - TODO: Does this help?
|
||||
@@ -85,10 +81,28 @@ func (enc *Encode) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyh
|
||||
defer w.(*responseWriter).Close()
|
||||
break
|
||||
}
|
||||
|
||||
return next.ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
func (enc *Encode) addEncoding(e Encoding) error {
|
||||
ae := e.AcceptEncoding()
|
||||
if ae == "" {
|
||||
return fmt.Errorf("encoder does not specify an Accept-Encoding value")
|
||||
}
|
||||
if _, ok := enc.writerPools[ae]; ok {
|
||||
return fmt.Errorf("encoder already added: %s", ae)
|
||||
}
|
||||
if enc.writerPools == nil {
|
||||
enc.writerPools = make(map[string]*sync.Pool)
|
||||
}
|
||||
enc.writerPools[ae] = &sync.Pool{
|
||||
New: func() interface{} {
|
||||
return e.NewEncoder()
|
||||
},
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// openResponseWriter creates a new response writer that may (or may not)
|
||||
// encode the response with encodingName. The returned response writer MUST
|
||||
// be closed after the handler completes.
|
||||
|
||||
Reference in New Issue
Block a user