private void ParseAccept(Headers headers, HashMap <Var> args) { var accept = headers[HeaderNames.Accept] ?? ""; var acceptCharset = headers[HeaderNames.AcceptCharset] ?? ""; var acceptEncoding = headers[HeaderNames.AcceptEncoding] ?? ""; var mimeTypes = ( from token in accept.Split(',').NonNullOrWhitespace() let part = token.Split(';').NonNullOrWhitespace() let type = part.First().Trim() let weight = part.Skip(1).FirstOrDefault()?.Trim().Replace("q=", "") orderby weight descending select type ).ToList(); var encodings = ( from token in acceptCharset.Split(',').NonNullOrWhitespace() let part = token.Split(';').NonNullOrWhitespace() let mime = part.First().Trim() let weight = part.Skip(1).FirstOrDefault()?.Trim().Replace("q=", "") orderby weight descending select GetEncoding(mime) ).ToList(); var compressions = ( from token in acceptEncoding.Split(',').NonNullOrWhitespace() let part = token.Split(';').NonNullOrWhitespace() let type = part.First().Trim() let weight = part.Skip(1).FirstOrDefault()?.Trim().Replace("q=", "") orderby weight descending select type ).ToList(); var format = args["f"]; if (format?.IsValue == true) { var modifier = format.Value.ToString(); var tokens = modifier.Split(';'); var mimeType = tokens.First(); var charset = tokens.Skip(1).FirstOrDefault()?.Split('=').Last(); mimeType = MediaSerializer.ParseFormat(mimeType) ?? mimeType; mimeTypes = new List <string> { mimeType }; if (mimeType.ContainsIgnoreCase(".zip")) { compressions = new List <string> { "deflate" }; } else if (mimeType.ContainsIgnoreCase(".gz")) { compressions = new List <string> { "gzip" }; } if (charset != null) { encodings = new List <Encoding> { GetEncoding(charset) }; } } this.MimeTypes = mimeTypes; this.Encodings = encodings; this.Compressions = compressions; }
public AcceptHeader(Headers headers, HashMap <Var> args) { ParseAccept(headers, args); }