1

I would like to parse an HTTP Accept Header in javascript, is anyone aware of an existing component that does so?

Marijn Huizendveld
  • 791
  • 2
  • 7
  • 23
  • You can find some information [here](http://stackoverflow.com/questions/220231/accessing-http-headers-in-javascript) –  Oct 18 '11 at 09:50
  • @Quentin: It is a string that is formed like an accept header. The source is not relevant (in this case it's provided by an external script). Basically I want to parse a string formatted like an accept header and return a list of preferred content types ordered by preferential level. – Marijn Huizendveld Oct 18 '11 at 14:55
  • @user973254 thanks but the answers in that thread are oriented towards the language part of the Accept Header. I need to parse it for content type preferences. – Marijn Huizendveld Oct 18 '11 at 14:58
  • There's no difference between Accept-Language and Accept except one has ISO language codes and one has content-types. You can use the same algorithm for both. – Quentin Oct 18 '11 at 16:04
  • @Quentin, true. Exactly why I'm asking this question, is anyone aware of an existing component that does so? – Marijn Huizendveld Oct 20 '11 at 12:06

1 Answers1

1

I wrote a standards based version of this in JavaScript, it is used by CouchDB, you can use it too:

http://code.google.com/p/mimeparse/source/browse/trunk/mimeparse.js

J Chris A
  • 1,014
  • 8
  • 12