public EncodingLookupResult GetResponseEncoder(string acceptEncoding) { EncodingLookupResult result = null; IEnumerable<EncodingType> encodingTypes = acceptEncoding.AsEncodingTypes(); EncodingType[] excludeTypes = encodingTypes.Where(e => e.QValue <= 0).ToArray(); foreach (EncodingType encodingType in encodingTypes) { if (encodingType.QValue > 0) { bool found = false; foreach (IEncoding encoding in this.Encodings) { if (encoding.CanEncode(encodingType) && !excludeTypes.Any(x => encoding.CanEncode(x))) { result = new EncodingLookupResult() { Encoding = encoding, EncodingType = encodingType }; found = true; break; } } if (found) { break; } } } // The spec says that the identity encoding can always be used. if (result == null) { result = ResolvedService.DefaultEncodingLookupResult; } return result; }
public EncodingLookupResult GetRequestDecoder(string contentEncoding) { EncodingLookupResult result = null; EncodingType encodingType = EncodingType.Parse(contentEncoding); if (encodingType != EncodingType.Empty) { foreach (IEncoding encoding in this.Encodings) { if (encoding.CanDecode(encodingType)) { result = new EncodingLookupResult() { Encoding = encoding, EncodingType = encodingType }; break; } } } else { result = ResolvedService.DefaultEncodingLookupResult; } return result; }