github.com/chenbh/concourse/v6@v6.4.2/atc/wrappa/compression_wrappa.go (about)

     1  package wrappa
     2  
     3  import (
     4  	"code.cloudfoundry.org/lager"
     5  	"github.com/NYTimes/gziphandler"
     6  	"github.com/chenbh/concourse/v6/atc"
     7  	"github.com/tedsuo/rata"
     8  )
     9  
    10  type CompressionWrappa struct {
    11  	lager.Logger
    12  }
    13  
    14  func NewCompressionWrappa(logger lager.Logger) Wrappa {
    15  	return CompressionWrappa{
    16  		logger,
    17  	}
    18  }
    19  
    20  func (wrappa CompressionWrappa) Wrap(handlers rata.Handlers) rata.Handlers {
    21  	wrapped := rata.Handlers{}
    22  
    23  	for name, handler := range handlers {
    24  		switch name {
    25  		// always gzip for events
    26  		case atc.BuildEvents:
    27  			gzipEnforcedHandler, err := gziphandler.GzipHandlerWithOpts(gziphandler.MinSize(0))
    28  			if err != nil {
    29  				wrappa.Logger.Error("failed-to-create-gzip-handler", err)
    30  			}
    31  
    32  			wrapped[name] = gzipEnforcedHandler(handler)
    33  		// skip gzip as this endpoint does it already
    34  		case atc.DownloadCLI:
    35  			wrapped[name] = handler
    36  		default:
    37  			wrapped[name] = gziphandler.GzipHandler(handler)
    38  		}
    39  	}
    40  
    41  	return wrapped
    42  }