@@ -48,8 +48,8 @@ func (s HdrState) String() string {
4848type Header struct {
4949 id int
5050 name string
51- values []HdrValue // Keeps track of the headers after VCL code execution
52- receivedValues []HdrValue // Keeps track of the headers that were sent by the client
51+ values []HdrValue // Keeps track of the headers after VCL code execution + original received headers
52+ receivedValues []HdrValue // Keeps track of the headers that were sent by the client (original received headers)
5353}
5454
5555func (h Header ) MarshalJSON () ([]byte , error ) {
@@ -87,7 +87,7 @@ type HdrValue struct {
8787}
8888
8989func (h HdrValue ) String () string {
90- return fmt .Sprintf ("Value: %s, State: %s" , h .value , h .state )
90+ return fmt .Sprintf ("{ Value: %s, State: %s} " , h .value , h .state )
9191}
9292
9393func (h HdrValue ) MarshalJSON () ([]byte , error ) {
@@ -117,6 +117,7 @@ type Headers map[string]Header
117117// Add adds a header value to the Headers map.
118118// If the header already exists, the value is appended.
119119// Otherwise, a new Header is created.
120+ //
120121// If the state is 'modified', previous values are discarded
121122// as Varnish VCL removes all the previous values on 'set' and 'unset'.
122123func (h Headers ) Add (name string , value string , state HdrState ) {
@@ -138,7 +139,7 @@ func (h Headers) Add(name string, value string, state HdrState) {
138139 // A check must be done before calling Add to determine
139140 // if the modified state should be used
140141 //
141- // If the header name is Host, it also accepts an unique value
142+ // If the header name is Host, do the same since it should have a unique value.
142143 if state == HdrStateModified || name == HdrNameHost {
143144 header .values = []HdrValue {}
144145 }
@@ -169,19 +170,17 @@ func (h Headers) Delete(name string) {
169170 return
170171 }
171172
172- // Mark all values as deleted
173+ // Mark all values as deleted only in the values slice.
174+ // The receivedValues slice is immutable.
173175 for i := range header .values {
174176 header .values [i ].state = HdrStateDeleted
175177 }
176- // Client send-headers cannot be deleted, if that happens it was inside of Varnish C code
177- // for i := range header.receivedValues {
178- // header.receivedValues[i].state = HdrStateDeleted
179- // }
180178
181179 h [name ] = header
182180}
183181
184- // Values returns all the values associated with the given header name
182+ // Values returns all the values associated with the given header name.
183+ //
185184// When received is true, it returns the values from the receivedValues slice.
186185func (h Headers ) Values (name string , received bool ) []HdrValue {
187186 name = CanonicalHeaderName (name )
@@ -196,8 +195,9 @@ func (h Headers) Values(name string, received bool) []HdrValue {
196195}
197196
198197// Get gets the first value associated with the given header name.
198+ //
199199// When received is true it only returns values from the receivedValues slice.
200- // If there are no values it returns ""
200+ // If there are no values it returns an empty string.
201201func (h Headers ) Get (name string , received bool ) string {
202202 name = CanonicalHeaderName (name )
203203 header , exists := h [name ]
0 commit comments