Mercurial Hosting > luan
comparison src/org/eclipse/jetty/server/Request.java @ 998:bf176925e00f
remove Request.getReader()
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 18 Oct 2016 23:01:00 -0600 |
parents | 7d28be82ab75 |
children | 32d4b569567c |
comparison
equal
deleted
inserted
replaced
997:7d28be82ab75 | 998:bf176925e00f |
---|---|
63 import javax.servlet.http.Part; | 63 import javax.servlet.http.Part; |
64 | 64 |
65 import org.eclipse.jetty.http.HttpCookie; | 65 import org.eclipse.jetty.http.HttpCookie; |
66 import org.eclipse.jetty.http.HttpFields; | 66 import org.eclipse.jetty.http.HttpFields; |
67 import org.eclipse.jetty.http.HttpHeaders; | 67 import org.eclipse.jetty.http.HttpHeaders; |
68 import org.eclipse.jetty.http.HttpMethods; | |
69 import org.eclipse.jetty.http.HttpParser; | 68 import org.eclipse.jetty.http.HttpParser; |
70 import org.eclipse.jetty.http.HttpStatus; | 69 import org.eclipse.jetty.http.HttpStatus; |
71 import org.eclipse.jetty.http.HttpURI; | 70 import org.eclipse.jetty.http.HttpURI; |
72 import org.eclipse.jetty.http.HttpVersions; | 71 import org.eclipse.jetty.http.HttpVersions; |
73 import org.eclipse.jetty.http.MimeTypes; | 72 import org.eclipse.jetty.http.MimeTypes; |
123 public final class Request implements HttpServletRequest | 122 public final class Request implements HttpServletRequest |
124 { | 123 { |
125 private static final Logger LOG = LoggerFactory.getLogger(Request.class); | 124 private static final Logger LOG = LoggerFactory.getLogger(Request.class); |
126 | 125 |
127 private static final Collection __defaultLocale = Collections.singleton(Locale.getDefault()); | 126 private static final Collection __defaultLocale = Collections.singleton(Locale.getDefault()); |
128 private static final int __NONE = 0, _STREAM = 1, __READER = 2; | 127 private static final int __NONE = 0, _STREAM = 1; |
129 | 128 |
130 private volatile Attributes _attributes; | 129 private volatile Attributes _attributes; |
131 private MultiMap<String> _baseParameters; | 130 private MultiMap<String> _baseParameters; |
132 private String _characterEncoding; | 131 private String _characterEncoding; |
133 protected final AbstractHttpConnection _connection; | 132 protected final AbstractHttpConnection _connection; |
143 private boolean _paramsExtracted; | 142 private boolean _paramsExtracted; |
144 private String _pathInfo; | 143 private String _pathInfo; |
145 private int _port; | 144 private int _port; |
146 private String _protocol = HttpVersions.HTTP_1_1; | 145 private String _protocol = HttpVersions.HTTP_1_1; |
147 private String _queryString; | 146 private String _queryString; |
148 private BufferedReader _reader; | |
149 private String _readerEncoding; | 147 private String _readerEncoding; |
150 private String _requestURI; | 148 private String _requestURI; |
151 private String _scheme = URIUtil.HTTP; | 149 private String _scheme = URIUtil.HTTP; |
152 private String _serverName; | 150 private String _serverName; |
153 private long _timeStamp; | 151 private long _timeStamp; |
192 if (content_type != null && content_type.length() > 0) | 190 if (content_type != null && content_type.length() > 0) |
193 { | 191 { |
194 content_type = HttpFields.valueParameters(content_type,null); | 192 content_type = HttpFields.valueParameters(content_type,null); |
195 | 193 |
196 if (MimeTypes.FORM_ENCODED.equalsIgnoreCase(content_type) && _inputState == __NONE | 194 if (MimeTypes.FORM_ENCODED.equalsIgnoreCase(content_type) && _inputState == __NONE |
197 && (HttpMethods.POST.equals(getMethod()) || HttpMethods.PUT.equals(getMethod()))) | 195 && ("POST".equals(getMethod()) || "PUT".equals(getMethod()))) |
198 { | 196 { |
199 int content_length = getContentLength(); | 197 int content_length = getContentLength(); |
200 if (content_length != 0) | 198 if (content_length != 0) |
201 { | 199 { |
202 try | 200 try |
370 } | 368 } |
371 | 369 |
372 @Override | 370 @Override |
373 public ServletInputStream getInputStream() throws IOException | 371 public ServletInputStream getInputStream() throws IOException |
374 { | 372 { |
375 if (_inputState != __NONE && _inputState != _STREAM) | |
376 throw new IllegalStateException("READER"); | |
377 _inputState = _STREAM; | 373 _inputState = _STREAM; |
378 return _connection.getInputStream(); | 374 return _connection.getInputStream(); |
379 } | 375 } |
380 | 376 |
381 @Override | 377 @Override |
550 } | 546 } |
551 | 547 |
552 @Override | 548 @Override |
553 public BufferedReader getReader() throws IOException | 549 public BufferedReader getReader() throws IOException |
554 { | 550 { |
555 if (_inputState != __NONE && _inputState != __READER) | 551 throw new UnsupportedOperationException(); |
556 throw new IllegalStateException("STREAMED"); | |
557 | |
558 if (_inputState == __READER) | |
559 return _reader; | |
560 | |
561 String encoding = getCharacterEncoding(); | |
562 if (encoding == null) | |
563 encoding = StringUtil.__ISO_8859_1; | |
564 | |
565 if (_reader == null || !encoding.equalsIgnoreCase(_readerEncoding)) | |
566 { | |
567 final ServletInputStream in = getInputStream(); | |
568 _readerEncoding = encoding; | |
569 _reader = new BufferedReader(new InputStreamReader(in,encoding)) | |
570 { | |
571 @Override | |
572 public void close() throws IOException | |
573 { | |
574 in.close(); | |
575 } | |
576 }; | |
577 } | |
578 _inputState = __READER; | |
579 return _reader; | |
580 } | 552 } |
581 | 553 |
582 @Override | 554 @Override |
583 public String getRealPath(String path) | 555 public String getRealPath(String path) |
584 { | 556 { |
891 return false; | 863 return false; |
892 } | 864 } |
893 | 865 |
894 protected void recycle() | 866 protected void recycle() |
895 { | 867 { |
896 if (_inputState == __READER) | |
897 { | |
898 try | |
899 { | |
900 int r = _reader.read(); | |
901 while (r != -1) | |
902 r = _reader.read(); | |
903 } | |
904 catch (Exception e) | |
905 { | |
906 LOG.trace("",e); | |
907 _reader = null; | |
908 } | |
909 } | |
910 | |
911 _handled = false; | 868 _handled = false; |
912 if (_contextHandler != null) | 869 if (_contextHandler != null) |
913 throw new IllegalStateException("Request in context!"); | 870 throw new IllegalStateException("Request in context!"); |
914 if (_attributes != null) | 871 if (_attributes != null) |
915 _attributes.clearAttributes(); | 872 _attributes.clearAttributes(); |