From: Ian B. <ia...@co...> - 2002-06-04 05:47:26
|
On Mon, 2002-06-03 at 19:58, Chris Prinos wrote: > In HTTPRequest.__init__, there's a bunch of code that set's up the request > data, in particular the initialization of the fields from self._input. The > problem is that the code assumes the incoming Content-type is > application/x-www-form-urlencoded, although it doesn't explicity check that > is the case. If the incoming data has a different content type, the data is > lost once the self._input stream is passed to FieldStorage.FieldStorage > becase it consumes the stream. You can see two special cases for 'text/xml' > and 'text/python/pickled/dict' that do something with self._input before > FieldStorage gets to it, but it's not a very extensible method of doing > things. There aren't any places in that __init__ method to dispatch > different handlers based on content-type, so even sublcassing is going to > duplicate a lot of code. Yes, this does appear to be a problem. There is some testing in FieldStorage as to the content-type, but if no content-type is given it assumes application/x-www-form-urlencoded. I assume this is because some clients do not set the content-type, and that this behavior should maintained for compatibility. I was looking at the FieldStorage code, and I couldn't quite figure out what happens when it gets a different content-type -- it seems to keep it somewhere (directly in .value of the FieldStorage instance?) If it does, I don't believe the Webware code will give access to it -- changing this would make xmlInput/dictInput unnecessary and probably be better all around. However, this doesn't solve your problem as you were talking about non-urlencoded input with no content-type to indicate that... if at all possible, I'd change these clients. text/xml will work (though be inaccurate), while text/plain seems more appropriate. To capture the input with no content-type, there'd have to be some setting to copy the input before it was sent to FieldStorage (it probably shouldn't do this by default, as it would consume more memory and web services *should* pass proper content-types, though that won't help you yet). I feel like any dispatching can probably best be done in the servlet itself. Ian |