Permalink
Browse files

Proper extraction of media-type from content-type field.

Previously POST request bodies were ignored with relatively recent
versions of Firefox, due to not extracting
"application/x-www-form-urlencoded" from
"application/x-www-form-urlencoded; charset=UTF-8"
(extra charset parameter set by Firefox when doing an XMLHttpRequest;
Opera/Chromium/Safari don't do this; don't know about other contexts).
  • Loading branch information...
mjambon committed Apr 24, 2012
1 parent 093fd27 commit 7b027eeef48cb2c4342dce532fd40cd6eb8d8beb
Showing with 12 additions and 2 deletions.
  1. +12 −2 lib/request.ml
View
@@ -39,6 +39,16 @@ type request = {
exception Length_required (* HTTP 411 *)
+let media_type_re =
+ (* Grab "foo/bar" from " foo/bar ; charset=UTF-8" *)
+ Re_str.regexp "[ \t]*\\([^ \t;]+\\)"
+
+let extract_media_type s =
+ if Re_str.string_match media_type_re s 0 then
+ Re_str.matched_group 1 s
+ else
+ ""
+
let init_request ~clisockaddr ~srvsockaddr finished ic =
lwt meth, uri, version = Parser.parse_request_fst_line ic in
let path = Uri.path uri in
@@ -64,8 +74,8 @@ let init_request ~clisockaddr ~srvsockaddr finished ic =
match meth with
| `POST -> begin
try
- let ct = List.assoc "content-type" headers in
- if ct = "application/x-www-form-urlencoded" then
+ let mt = extract_media_type (List.assoc "content-type" headers) in
+ if mt = "application/x-www-form-urlencoded" then
Message.string_of_body body >|=
(fun s -> Uri.query_of_encoded s, [`String s])
else return ([], body)

0 comments on commit 7b027ee

Please sign in to comment.