-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 Behrang,
On 12/12/19 03:56, Behrang Saeedzadeh wrote: > Chris, > > 1) Does it make sense to call ServletRequest#getInputStream after > ServletRequest#getReader? No, and consequently it will throw > IllegalStateException. 2) Does it make sense to call > ServletRequest#getInputStream after ServletRequest#getPart/s? No, > but it returns an empty stream instead of throwing > IllegalStateException. > > These behaviours are not consistent. Perhaps, but they do not violate the specification. Tomcat must call getInputStream to parse the various multipart/form-data parts. If you call getInputStream, too, there will be no error. I suspect if you call getReader, you'll find you'll get an IllegalStateException. > Best regards, > > { "blog" : "https://blog.behrang.org", "twitter": > "https://twitter.com/behrangsa", "github": > "https://github.com/behrangsa/", "stackoverflow": > "https://stackoverflow.com/users/309683?tab=profile"} Please stop advertising yourself on a public mailing list. - -chris > On Thu, Dec 12, 2019 at 4:31 AM Christopher Schultz < > ch...@christopherschultz.net> wrote: > > André, > > On 12/10/19 16:47, André Warnier (tomcat/perl) wrote: >>>> On 10.12.2019 15:31, Christopher Schultz wrote: >>>>> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 >>>>> >>>>> Behrang, >>>>> >>>>> On 12/8/19 05:18, Behrang Saeedzadeh wrote: >>>>>> If I call javax.servlet.ServletRequest#getInputStream >>>>>> after having called >>>>>> javax.servlet.http.HttpServletRequest#getPart, even >>>>>> without performing any operations on the given part, I >>>>>> am getting an empty stream (0-bytes). >>>>>> >>>>>> Is this in compliance with the spec? >>>>> >>>>> What does the servlet spec say about that situation? >>>>> >>>> >>>> A bit in defense of the OP, I have to say that the Servlet >>>> Spec (4.0 final) does not seem extremely clear on that >>>> subject. > > While I appreciate your research activities, I was hoping the OP > would actually read the spec to get some clarification. > >>>> In section "3.1.1 When Parameters Are Available", it /does/ >>>> say this : >>>> >>>> "If the conditions are met, post form data will no longer be >>>> available for reading directly from the request object’s >>>> input stream." >>>> >>>> But among those conditions that have to be met (just above >>>> that quote) is "4. The servlet has made an initial call of >>>> any of the "getParameter family" of methods on the request >>>> object." >>>> >>>> (So there, it talks about "the getParameter family", not the >>>> "getPart" ones). >>>> >>>> It only talks about the "getPart" methods in the next section >>>> "3.2 File upload", and in that section, all it says about the >>>> input stream is : "If the servlet container does not provide >>>> the multi-part/form-data processing, the data will be >>>> available through the HttpServletReuqest.getInputStream." >>>> >>>> So the way I read this, is that there is nothing that >>>> explicitly says that the InputStream is no longer available >>>> if you have called "getPart". > > The only reason the container would process multi-part/form-data > requests is if you called request.getPart*. Therefore, the > InputStream is no longer available. > >>>> (It is also in fact not very clear about what happens to the >>>> parameters, when the content-type of the Request is >>>> "multipart/form-data", which is only mentioned in section >>>> 3.2.) > > Normal parameters are available via request.getParameter*. You can > also go through the agony of getPart("foo").getInputStream() if > you'd like. This is documented in section 3.2 "File Upload". > >>>> On the other hand, >>>> http://tomcat.apache.org/tomcat-9.0-doc/servletapi/index.html >>>> --> Interface HttpServletRequest says : >>>> >>>> Part getPart(java.lang.String name) throws >>>> java.io.IOException, ServletException Gets the named Part or >>>> null if the Part does not exist. *Triggers upload of all >>>> Parts*. (emphasis mine) >>>> >>>> which /may/ be taken to mean (and probably does) that it >>>> consumes the whole InputStream. > > It does. And, necessarily, it must. You can't find out what's in > the request entity without ... reading the request entity. > >>>> But again, this may be lacking some overall clarity. >>>> >>>> In any case, the OP's question is not really unwarranted, >>>> unless there is some other explanation somewhere which I have >>>> missed. > > I guess to me this falls under the category of "obvious", but then > again I know quite a bit about this subject. > > -chris >> >> --------------------------------------------------------------------- >> >> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org >> For additional commands, e-mail: users-h...@tomcat.apache.org >> >> > -----BEGIN PGP SIGNATURE----- Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/ iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl3yV8AACgkQHPApP6U8 pFh11hAAvJ4wdKJLUW89Xgk0oJa7HtaqVuFkDTSwPZ0NfRSs372eQO6N503d3vjp SPlros1irLmmtFnDWN4b3/t/oJRirdExbiEjPP8hiRynGm7V3RT+naVmvm5ksyL8 RbEXbiD1Gu0/UcrR+uSr1Omxa9rxb18uyBDrUw/WmXZVu0k/geRabyrAXvTKIJaa MMXrK8sxAG5Yk6dXu3Lm1qgx1d8vo1oeoGfbAxCGiaQ0EwOHLpn2PTce/39s9EmI +8MhIDfEy8O1ZSSoLnInSxka6zgP6n3yk7onGIgzIkE4YwZTXOPKh/s4GZNXg2ly 5/600W3AuOT4ymDNdvw9Hx64PnfElo85WgL2iPSi1NfPmKjNxJKFDKB//W5GAGgk us51bWkFf4wRaUSTHBKty0xipEoy8EJA/P2TWm8JWNcHXF+CDuPq54ygK6iYT2XL RTSRflC5EiUA1NfAIhVgwFjN3L/aUMrRaAzEqFQKK1Z/7z3W5Ql4dRAgdq75QAE+ XpYynPEHfWABR7VwbmplVXMsjGfvqc5Ry6AK3gwdsERryrZBezdLZHnojLcxMDaQ 3refYsMGM3h79O4zd30quGJx72nW6/DsotfYLsGHw6iZMvzdhNPOiLZu44LoIS3D juhbDbJNAothwwNCnAV0GSueqcMPo8N4bYYA4yL3x7WgKLuRLAU= =RHsI -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org