Robert Kern wrote: > Please > follow our advice. Split using b'\r\n\r\n' and use the maxsplit=1 argument to > make sure that you do not split on spurious b'\r\n\r\n' sequences inside the > JPEG body. Do not decode the bytes.
Correct, and I'll add that this is a case where we might want to be better than correct. BaseHTTPRequestHandler in the Python standard library accommodates clients that incorrectly omit the '\r' and end header lines with just '\n'. Such apps have been seen in the wild. Since bare '\n' never appears in correctly formed HTTP headers, interpreting it as equivalent to '\r\n' doesn't break anything. The re module offers a split that does what we want. import re boundary_re = re.compile(br'\r?\n\r?\n') then you can use: (headers, content) = boundary_re.split(rawdata, 1) I like Robert's suggestion to use the HTTP server or wsgiref in the Python library. There's significant arcane wisdom programmed in already. -- http://mail.python.org/mailman/listinfo/python-list