@@ -34,30 +34,56 @@ func (ah AcceptHeader) Less(i, j int) bool {
3434 return ah .mheaders [i ].Quality < ah .mheaders [j ].Quality
3535 }
3636
37+ less , done := ah .lessWildcard (i , j )
38+ if done {
39+ return less
40+ }
41+
42+ return ah .lessParams (i , j )
43+ }
44+
45+ func (ah AcceptHeader ) lessParams (i , j int ) bool {
46+ li := len (ah .mheaders [i ].Params )
47+ _ , ok := ah .mheaders [i ].Params ["q" ]
48+
49+ if ok {
50+ li --
51+ }
52+
53+ lj := len (ah .mheaders [j ].Params )
54+ _ , ok = ah .mheaders [j ].Params ["q" ]
55+
56+ if ok {
57+ lj --
58+ }
59+
60+ return li < lj
61+ }
62+
63+ func (ah AcceptHeader ) lessWildcard (i , j int ) (less , done bool ) {
3764 // '*' value has less priority than a specific type
3865 // If i contains '*' and j has specific type, then i less than j
3966 if ah .mheaders [i ].Type == MimeAny && ah .mheaders [j ].Type != MimeAny {
40- return true
67+ return true , true
4168 }
4269
4370 // If i contains a specific type and j contains '*' then i greater than j
4471 if ah .mheaders [i ].Type != MimeAny && ah .mheaders [j ].Type == MimeAny {
45- return false
72+ return false , true
4673 }
4774
4875 // '*' value has less priority than a specific type
4976 // If i contains '*' and j has specific type, then i less than j
5077 if ah .mheaders [i ].Subtype == MimeAny && ah .mheaders [j ].Subtype != MimeAny {
51- return true
78+ return true , true
5279 }
5380
5481 // If i contains a specific type and j contains '*' then i greater than j
5582 if ah .mheaders [i ].Subtype != MimeAny && ah .mheaders [j ].Subtype == MimeAny {
56- return false
83+ return false , true
5784 }
5885
59- // More specific params has greater priority
60- return len (ah .mheaders [i ].Params ) < len (ah .mheaders [j ].Params )
86+ return false , false
6187}
6288
6389// Swap function for sort.Interface interface.
0 commit comments