github.com/yandex/pandora@v0.5.32/components/providers/http/decoders/ammo/raw_ammo.go (about)

     1  package ammo
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"github.com/yandex/pandora/components/providers/http/decoders/raw"
     7  	"github.com/yandex/pandora/components/providers/http/util"
     8  	"golang.org/x/xerrors"
     9  )
    10  
    11  type RawAmmo struct {
    12  	buff          []byte
    13  	filePosition  int64
    14  	tag           string
    15  	commonHeaders http.Header
    16  }
    17  
    18  func (a *RawAmmo) BuildRequest() (*http.Request, error) {
    19  	req, err := raw.DecodeRequest(a.buff)
    20  	if err != nil {
    21  		return nil, xerrors.Errorf("failed to decode ammo with err: %w, at position: %v; data: %q", err, a.filePosition, a.buff)
    22  	}
    23  	util.EnrichRequestWithHeaders(req, a.commonHeaders)
    24  	return req, nil
    25  }
    26  
    27  func (a *RawAmmo) Tag() string {
    28  	return a.tag
    29  }
    30  
    31  func (a *RawAmmo) Setup(buff []byte, tag string, filePosition int64, header http.Header) {
    32  	a.buff = buff
    33  	a.tag = tag
    34  	a.filePosition = filePosition
    35  	a.commonHeaders = header.Clone()
    36  }
    37  
    38  func (a *RawAmmo) Reset() {
    39  	a.buff = nil
    40  	a.filePosition = 0
    41  	a.tag = ""
    42  	a.commonHeaders = nil
    43  }