-
Notifications
You must be signed in to change notification settings - Fork 0
test: Santosh test #1
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,7 +93,8 @@ type Decoder struct { | |
// to fully parse before. Unlike buf, we own this data. | ||
saveBuf bytes.Buffer | ||
|
||
firstField bool // processing the first field of the header block | ||
firstField bool // processing the first field of the header block | ||
allowMissingFields bool | ||
} | ||
|
||
// NewDecoder returns a new decoder with the provided maximum dynamic | ||
|
@@ -123,6 +124,10 @@ func (d *Decoder) SetMaxStringLength(n int) { | |
d.maxStrLen = n | ||
} | ||
|
||
func (d *Decoder) SetAllowMissingFields(v bool) { | ||
d.allowMissingFields = v | ||
} | ||
|
||
// SetEmitFunc changes the callback used when new header fields | ||
// are decoded. | ||
// It must be non-nil. It does not affect EmitEnabled. | ||
|
@@ -343,6 +348,10 @@ func (d *Decoder) parseFieldIndexed() error { | |
} | ||
hf, ok := d.at(idx) | ||
if !ok { | ||
if d.allowMissingFields { | ||
d.buf = buf | ||
return d.callEmit(HeaderField{Name: fmt.Sprintf("missing-index-%d", idx), Value: "none"}) | ||
} | ||
Comment on lines
+351
to
+354
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's an inconsistency in how missing fields are handled. In There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is if complete header filed is indexed. (key and value) |
||
return DecodingError{InvalidIndexError(idx)} | ||
} | ||
d.buf = buf | ||
|
@@ -363,9 +372,13 @@ func (d *Decoder) parseFieldLiteral(n uint8, it indexType) error { | |
if nameIdx > 0 { | ||
ihf, ok := d.at(nameIdx) | ||
if !ok { | ||
return DecodingError{InvalidIndexError(nameIdx)} | ||
if !d.allowMissingFields { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should have some unit tests to verify this logic. |
||
return DecodingError{InvalidIndexError(nameIdx)} | ||
} | ||
hf.Name = fmt.Sprintf("missing-index-%d", nameIdx) | ||
} else { | ||
hf.Name = ihf.Name | ||
} | ||
hf.Name = ihf.Name | ||
} else { | ||
t-santoshsahu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
undecodedName, buf, err = d.readString(buf) | ||
if err != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new public API function should have documentation explaining its purpose and behavior, similar to other public methods in this file.