Normalizing the Accept header

Difficulty level: Medium

Objective

This challenge includes both a template for the accept.media_lookup function, as well as five unique test requests.

Each request includes a different Accept header value, which needs to be normalized prior to passing to the origin. Although the normalization is handled by the accept.media_lookup function, it is your job to fill in the function with the proper values so that when the code runs, the preferred Accept values are sent for each test request. The test requests we send and the expected transformation of the Accept header are shown below:

Client request's Accept headerExpected origin request's Accept header
application/, application/vnd.api+json, text/html;q=0.9, /*;q=0.1,application/vnd.api+json
application/*application/x-www-form-urlencoded
/text/html
text/css, text/html, text/xml, text/csv, text/plain, image/png, image/jpeg, image/gifimage/jpeg
text/, application/;q=0.9, /;q=0.1,text/plain

Fill in the accept.media_lookup template to ensure the Accept header that is passed to the origin for each request satisfies the test assigned to that given request. You can see what each request is expecting for the Accept value by looking at the test associated with that request.

Try this challenge now

For a guide to how challenges work see getting started.

User contributed notes

BETA

Do you see an error in this page? Do have an interesting use case, example or edge case people should know about? Share your knowledge and help people who are reading this page! (Comments are moderated; for support, please contact support@fastly.com)