@@ -3040,7 +3040,7 @@ func TestSliceHeader(t *testing.T) {
30403040 require_True (t , bytes .Equal (sliced , copied ))
30413041}
30423042
3043- func TestSliceHeaderOrdering (t * testing.T ) {
3043+ func TestSliceHeaderOrderingPrefix (t * testing.T ) {
30443044 hdr := []byte ("NATS/1.0\r \n \r \n " )
30453045
30463046 // These headers share the same prefix, the longer subject
@@ -3060,6 +3060,105 @@ func TestSliceHeaderOrdering(t *testing.T) {
30603060 require_True (t , bytes .Equal (sliced , copied ))
30613061}
30623062
3063+ func TestSliceHeaderOrderingSuffix (t * testing.T ) {
3064+ hdr := []byte ("NATS/1.0\r \n \r \n " )
3065+
3066+ // These headers share the same suffix, the longer subject
3067+ // must not invalidate the existence of the shorter one.
3068+ hdr = genHeader (hdr , "Previous-Nats-Msg-Id" , "user" )
3069+ hdr = genHeader (hdr , "Nats-Msg-Id" , "control" )
3070+
3071+ sliced := sliceHeader ("Nats-Msg-Id" , hdr )
3072+ copied := getHeader ("Nats-Msg-Id" , hdr )
3073+
3074+ require_NotNil (t , sliced )
3075+ require_NotNil (t , copied )
3076+ require_True (t , bytes .Equal (sliced , copied ))
3077+ require_Equal (t , string (copied ), "control" )
3078+ }
3079+
3080+ func TestRemoveHeaderIfPresentOrderingPrefix (t * testing.T ) {
3081+ hdr := []byte ("NATS/1.0\r \n \r \n " )
3082+
3083+ // These headers share the same prefix, the longer subject
3084+ // must not invalidate the existence of the shorter one.
3085+ hdr = genHeader (hdr , JSExpectedLastSubjSeqSubj , "foo" )
3086+ hdr = genHeader (hdr , JSExpectedLastSubjSeq , "24" )
3087+
3088+ hdr = removeHeaderIfPresent (hdr , JSExpectedLastSubjSeq )
3089+ ehdr := genHeader (nil , JSExpectedLastSubjSeqSubj , "foo" )
3090+ require_True (t , bytes .Equal (hdr , ehdr ))
3091+ }
3092+
3093+ func TestRemoveHeaderIfPresentOrderingSuffix (t * testing.T ) {
3094+ hdr := []byte ("NATS/1.0\r \n \r \n " )
3095+
3096+ // These headers share the same suffix, the longer subject
3097+ // must not invalidate the existence of the shorter one.
3098+ hdr = genHeader (hdr , "Previous-Nats-Msg-Id" , "user" )
3099+ hdr = genHeader (hdr , "Nats-Msg-Id" , "control" )
3100+
3101+ hdr = removeHeaderIfPresent (hdr , "Nats-Msg-Id" )
3102+ ehdr := genHeader (nil , "Previous-Nats-Msg-Id" , "user" )
3103+ require_True (t , bytes .Equal (hdr , ehdr ))
3104+ }
3105+
3106+ func TestSetHeaderOrderingPrefix (t * testing.T ) {
3107+ for _ , space := range []bool {true , false } {
3108+ title := "Normal"
3109+ if ! space {
3110+ title = "Trimmed"
3111+ }
3112+ t .Run (title , func (t * testing.T ) {
3113+ hdr := []byte ("NATS/1.0\r \n \r \n " )
3114+
3115+ // These headers share the same prefix, the longer subject
3116+ // must not invalidate the existence of the shorter one.
3117+ hdr = genHeader (hdr , JSExpectedLastSubjSeqSubj , "foo" )
3118+ hdr = genHeader (hdr , JSExpectedLastSubjSeq , "24" )
3119+ if ! space {
3120+ hdr = bytes .ReplaceAll (hdr , []byte (" " ), nil )
3121+ }
3122+
3123+ hdr = setHeader (JSExpectedLastSubjSeq , "12" , hdr )
3124+ ehdr := genHeader (nil , JSExpectedLastSubjSeqSubj , "foo" )
3125+ ehdr = genHeader (ehdr , JSExpectedLastSubjSeq , "12" )
3126+ if ! space {
3127+ ehdr = bytes .ReplaceAll (ehdr , []byte (" " ), nil )
3128+ }
3129+ require_True (t , bytes .Equal (hdr , ehdr ))
3130+ })
3131+ }
3132+ }
3133+
3134+ func TestSetHeaderOrderingSuffix (t * testing.T ) {
3135+ for _ , space := range []bool {true , false } {
3136+ title := "Normal"
3137+ if ! space {
3138+ title = "Trimmed"
3139+ }
3140+ t .Run (title , func (t * testing.T ) {
3141+ hdr := []byte ("NATS/1.0\r \n \r \n " )
3142+
3143+ // These headers share the same suffix, the longer subject
3144+ // must not invalidate the existence of the shorter one.
3145+ hdr = genHeader (hdr , "Previous-Nats-Msg-Id" , "user" )
3146+ hdr = genHeader (hdr , "Nats-Msg-Id" , "control" )
3147+ if ! space {
3148+ hdr = bytes .ReplaceAll (hdr , []byte (" " ), nil )
3149+ }
3150+
3151+ hdr = setHeader ("Nats-Msg-Id" , "other" , hdr )
3152+ ehdr := genHeader (nil , "Previous-Nats-Msg-Id" , "user" )
3153+ ehdr = genHeader (ehdr , "Nats-Msg-Id" , "other" )
3154+ if ! space {
3155+ ehdr = bytes .ReplaceAll (ehdr , []byte (" " ), nil )
3156+ }
3157+ require_True (t , bytes .Equal (hdr , ehdr ))
3158+ })
3159+ }
3160+ }
3161+
30633162func TestInProcessAllowedConnectionType (t * testing.T ) {
30643163 tmpl := `
30653164 listen: "127.0.0.1:-1"
0 commit comments