MCPcopy Create free account
hub / github.com/denoland/std / preferredEncodings

Function preferredEncodings

http/_negotiation/encoding.ts:143–164  ·  view source on GitHub ↗
(
  accept: string,
  provided?: string[],
)

Source from the content-addressed store, hash-verified

141 * negotiated encoding based on the `provided` encodings otherwise just a
142 * prioritized array of encodings. */
143export function preferredEncodings(
144 accept: string,
145 provided?: string[],
146): string[] {
147 const accepts = parseAcceptEncoding(accept);
148
149 if (!provided) {
150 return accepts
151 .filter(isQuality)
152 .sort(compareSpecs)
153 .map((spec) => spec.encoding!);
154 }
155
156 const priorities = provided.map((type, index) =>
157 getEncodingPriority(type, accepts, index)
158 );
159
160 return priorities
161 .filter(isQuality)
162 .sort(compareSpecs)
163 .map((priority) => provided[priorities.indexOf(priority)]!);
164}

Callers 1

acceptsEncodingsFunction · 0.90

Calls 2

parseAcceptEncodingFunction · 0.85
getEncodingPriorityFunction · 0.85

Tested by

no test coverage detected