storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/pkg/rpc/encoder_selector.go (about)

     1  // Copyright 2009 The Go Authors. All rights reserved.
     2  // Copyright 2012 The Gorilla Authors. All rights reserved.
     3  // Use of this source code is governed by a BSD-style
     4  // license that can be found in the LICENSE file.
     5  
     6  // Copyright 2020 MinIO, Inc. All rights reserved.
     7  // forked from https://github.com/gorilla/rpc/v2
     8  // modified to be used with MinIO under Apache
     9  // 2.0 license that can be found in the LICENSE file.
    10  
    11  package rpc
    12  
    13  import (
    14  	"io"
    15  	"net/http"
    16  )
    17  
    18  // Encoder interface contains the encoder for http response.
    19  // Eg. gzip, flate compressions.
    20  type Encoder interface {
    21  	Encode(w http.ResponseWriter) io.Writer
    22  }
    23  
    24  type encoder struct {
    25  }
    26  
    27  func (_ *encoder) Encode(w http.ResponseWriter) io.Writer {
    28  	return w
    29  }
    30  
    31  var DefaultEncoder = &encoder{}
    32  
    33  // EncoderSelector interface provides a way to select encoder using the http
    34  // request. Typically people can use this to check HEADER of the request and
    35  // figure out client capabilities.
    36  // Eg. "Accept-Encoding" tells about supported compressions.
    37  type EncoderSelector interface {
    38  	Select(r *http.Request) Encoder
    39  }
    40  
    41  type encoderSelector struct {
    42  }
    43  
    44  func (_ *encoderSelector) Select(_ *http.Request) Encoder {
    45  	return DefaultEncoder
    46  }
    47  
    48  var DefaultEncoderSelector = &encoderSelector{}