comparison src/org/eclipse/jetty/server/Request.java @ 990:83cc6e05a58f

remove special attribute handling
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 17 Oct 2016 05:50:47 -0600
parents 900e5b8ccd19
children 688c39c50ee3
comparison
equal deleted inserted replaced
989:900e5b8ccd19 990:83cc6e05a58f
149 private MultiMap<String> _parameters; 149 private MultiMap<String> _parameters;
150 private boolean _paramsExtracted; 150 private boolean _paramsExtracted;
151 private String _pathInfo; 151 private String _pathInfo;
152 private int _port; 152 private int _port;
153 private String _protocol = HttpVersions.HTTP_1_1; 153 private String _protocol = HttpVersions.HTTP_1_1;
154 private String _queryEncoding;
155 private String _queryString; 154 private String _queryString;
156 private BufferedReader _reader; 155 private BufferedReader _reader;
157 private String _readerEncoding; 156 private String _readerEncoding;
158 private String _remoteAddr; 157 private String _remoteAddr;
159 private String _remoteHost; 158 private String _remoteHost;
199 try 198 try
200 { 199 {
201 // Handle query string 200 // Handle query string
202 if (_uri != null && _uri.hasQuery()) 201 if (_uri != null && _uri.hasQuery())
203 { 202 {
204 if (_queryEncoding == null) 203 _uri.decodeQueryTo(_baseParameters);
205 _uri.decodeQueryTo(_baseParameters);
206 else
207 {
208 try
209 {
210 _uri.decodeQueryTo(_baseParameters,_queryEncoding);
211 }
212 catch (UnsupportedEncodingException e)
213 {
214 if (LOG.isDebugEnabled())
215 LOG.warn("",e);
216 else
217 LOG.warn(e.toString());
218 }
219 }
220 } 204 }
221 205
222 // handle any _content. 206 // handle any _content.
223 String encoding = getCharacterEncoding(); 207 String encoding = getCharacterEncoding();
224 String content_type = getContentType(); 208 String content_type = getContentType();
743 { 727 {
744 return _protocol; 728 return _protocol;
745 } 729 }
746 730
747 /* ------------------------------------------------------------ */ 731 /* ------------------------------------------------------------ */
748 public String getQueryEncoding()
749 {
750 return _queryEncoding;
751 }
752
753 /* ------------------------------------------------------------ */
754 /* 732 /*
755 * @see javax.servlet.http.HttpServletRequest#getQueryString() 733 * @see javax.servlet.http.HttpServletRequest#getQueryString()
756 */ 734 */
757 public String getQueryString() 735 public String getQueryString()
758 { 736 {
759 if (_queryString == null && _uri != null) 737 if (_queryString == null && _uri != null)
760 { 738 {
761 if (_queryEncoding == null) 739 _queryString = _uri.getQuery();
762 _queryString = _uri.getQuery();
763 else
764 _queryString = _uri.getQuery(_queryEncoding);
765 } 740 }
766 return _queryString; 741 return _queryString;
767 } 742 }
768 743
769 /* ------------------------------------------------------------ */ 744 /* ------------------------------------------------------------ */
1262 _serverName = null; 1237 _serverName = null;
1263 _method = null; 1238 _method = null;
1264 _pathInfo = null; 1239 _pathInfo = null;
1265 _port = 0; 1240 _port = 0;
1266 _protocol = HttpVersions.HTTP_1_1; 1241 _protocol = HttpVersions.HTTP_1_1;
1267 _queryEncoding = null;
1268 _queryString = null; 1242 _queryString = null;
1269 _requestURI = null; 1243 _requestURI = null;
1270 _scheme = URIUtil.HTTP; 1244 _scheme = URIUtil.HTTP;
1271 _servletPath = null; 1245 _servletPath = null;
1272 _timeStamp = 0; 1246 _timeStamp = 0;
1298 * 1272 *
1299 * @see javax.servlet.ServletRequest#setAttribute(java.lang.String, java.lang.Object) 1273 * @see javax.servlet.ServletRequest#setAttribute(java.lang.String, java.lang.Object)
1300 */ 1274 */
1301 public void setAttribute(String name, Object value) 1275 public void setAttribute(String name, Object value)
1302 { 1276 {
1303 Object old_value = _attributes == null?null:_attributes.getAttribute(name);
1304
1305 if (name.startsWith("org.eclipse.jetty."))
1306 {
1307 if ("org.eclipse.jetty.server.Request.queryEncoding".equals(name))
1308 setQueryEncoding(value == null?null:value.toString());
1309 else if ("org.eclipse.jetty.server.sendContent".equals(name))
1310 {
1311 try
1312 {
1313 ((AbstractHttpConnection.Output)getServletResponse().getOutputStream()).sendContent(value);
1314 }
1315 catch (IOException e)
1316 {
1317 throw new RuntimeException(e);
1318 }
1319 }
1320 else if ("org.eclipse.jetty.server.ResponseBuffer".equals(name))
1321 {
1322 try
1323 {
1324 final ByteBuffer byteBuffer = (ByteBuffer)value;
1325 synchronized (byteBuffer)
1326 {
1327 NIOBuffer buffer = byteBuffer.isDirect()?new DirectNIOBuffer(byteBuffer,true):new IndirectNIOBuffer(byteBuffer,true);
1328 ((AbstractHttpConnection.Output)getServletResponse().getOutputStream()).sendResponse(buffer);
1329 }
1330 }
1331 catch (IOException e)
1332 {
1333 throw new RuntimeException(e);
1334 }
1335 }
1336 else if ("org.eclipse.jetty.io.EndPoint.maxIdleTime".equalsIgnoreCase(name))
1337 {
1338 try
1339 {
1340 getConnection().getEndPoint().setMaxIdleTime(Integer.valueOf(value.toString()));
1341 }
1342 catch (IOException e)
1343 {
1344 throw new RuntimeException(e);
1345 }
1346 }
1347 }
1348
1349 if (_attributes == null) 1277 if (_attributes == null)
1350 _attributes = new AttributesMap(); 1278 _attributes = new AttributesMap();
1351 _attributes.setAttribute(name,value); 1279 _attributes.setAttribute(name,value);
1352 } 1280 }
1353
1354 /* ------------------------------------------------------------ */
1355 /*
1356 */
1357 public void setAttributes(Attributes attributes)
1358 {
1359 _attributes = attributes;
1360 }
1361
1362 /* ------------------------------------------------------------ */
1363 1281
1364 /* ------------------------------------------------------------ */ 1282 /* ------------------------------------------------------------ */
1365 /* 1283 /*
1366 * @see javax.servlet.ServletRequest#setCharacterEncoding(java.lang.String) 1284 * @see javax.servlet.ServletRequest#setCharacterEncoding(java.lang.String)
1367 */ 1285 */
1507 _protocol = protocol; 1425 _protocol = protocol;
1508 } 1426 }
1509 1427
1510 /* ------------------------------------------------------------ */ 1428 /* ------------------------------------------------------------ */
1511 /** 1429 /**
1512 * Set the character encoding used for the query string. This call will effect the return of getQueryString and getParamaters. It must be called before any
1513 * geParameter methods.
1514 *
1515 * The request attribute "org.eclipse.jetty.server.server.Request.queryEncoding" may be set as an alternate method of calling setQueryEncoding.
1516 *
1517 * @param queryEncoding
1518 */
1519 public void setQueryEncoding(String queryEncoding)
1520 {
1521 _queryEncoding = queryEncoding;
1522 _queryString = null;
1523 }
1524
1525 /* ------------------------------------------------------------ */
1526 /**
1527 * @param queryString 1430 * @param queryString
1528 * The queryString to set. 1431 * The queryString to set.
1529 */ 1432 */
1530 public void setQueryString(String queryString) 1433 public void setQueryString(String queryString)
1531 { 1434 {
1532 _queryString = queryString; 1435 _queryString = queryString;
1533 _queryEncoding = null; //assume utf-8
1534 } 1436 }
1535 1437
1536 /* ------------------------------------------------------------ */ 1438 /* ------------------------------------------------------------ */
1537 /** 1439 /**
1538 * @param addr 1440 * @param addr
1725 { 1627 {
1726 if (merge_old_query) 1628 if (merge_old_query)
1727 { 1629 {
1728 StringBuilder overridden_query_string = new StringBuilder(); 1630 StringBuilder overridden_query_string = new StringBuilder();
1729 MultiMap<String> overridden_old_query = new MultiMap<String>(); 1631 MultiMap<String> overridden_old_query = new MultiMap<String>();
1730 UrlEncoded.decodeTo(_queryString,overridden_old_query,getQueryEncoding());//decode using any queryencoding set for the request 1632 UrlEncoded.decodeTo(_queryString,overridden_old_query,null);//decode using any queryencoding set for the request
1731 1633
1732 1634
1733 MultiMap<String> overridden_new_query = new MultiMap<String>(); 1635 MultiMap<String> overridden_new_query = new MultiMap<String>();
1734 UrlEncoded.decodeTo(query,overridden_new_query,StringUtil.__UTF8); //have to assume utf8 as we cannot know otherwise 1636 UrlEncoded.decodeTo(query,overridden_new_query,StringUtil.__UTF8); //have to assume utf8 as we cannot know otherwise
1735 1637