Re: Parsing MIME-encoded data in an HTTP request
- From: s0suk3@xxxxxxxxx
- Date: Thu, 3 Jul 2008 20:50:45 -0700 (PDT)
On Jul 3, 3:59 pm, Ron Garret <rNOSPA...@xxxxxxxxxxx> wrote:
I'm writing a little HTTP server and need to parse request content that
is mime-encoded. All the MIME routines in the Python standard library
seem to have been subsumed into the email package, which makes this
operation a little awkward.
To deal with messages of that kind, I've seen modules such as
'rfc822', and 'mimetools' (which apparently builds itself from
'rfc822', so it might be more complete). There's also 'mimetypes', in
case you need to deal with file extensions and their corresponding
MIME media type.
It seems I have to do the following:
1. Extract the content-length header from the HTTP request and use that
to read the payload.
2. Stick some artificial-looking headers onto the beginning of this
payload to make it look like an email message (including the
content-type and content-transfer-encoding headers)
3. Parse the resulting string into a email message
Email? Why does an HTTP server need to build an email message?
I remember doing things like that some time ago when building an HTTP
server myself (http://code.google.com/p/sws-d/). Incidentally, I
resisted the urge to use much of the Python's library facilities (most
things are done manually; am I a knucklehead or what!? :). You might
wanna take a look to get some ideas.
Sebastian
.
- Follow-Ups:
- Re: Parsing MIME-encoded data in an HTTP request
- From: Ron Garret
- Re: Parsing MIME-encoded data in an HTTP request
- References:
- Parsing MIME-encoded data in an HTTP request
- From: Ron Garret
- Parsing MIME-encoded data in an HTTP request
- Prev by Date: Re: HTTP request error with urlopen
- Next by Date: Nested generator caveat
- Previous by thread: Parsing MIME-encoded data in an HTTP request
- Next by thread: Re: Parsing MIME-encoded data in an HTTP request
- Index(es):