📄 request.java
字号:
{ Log.ignore(e); } } } if (_userPrincipal == SecurityHandler.__NO_USER) return null; return _userPrincipal; } /* ------------------------------------------------------------ */ /* * @see javax.servlet.http.HttpServletRequest#getQueryString() */ public String getQueryString() { if (_queryString==null && _uri!=null) { if (_queryEncoding==null) _queryString=_uri.getQuery(); else _queryString=_uri.getQuery(_queryEncoding); } return _queryString; } /* ------------------------------------------------------------ */ /* * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromCookie() */ public boolean isRequestedSessionIdFromCookie() { return _requestedSessionId!=null && _requestedSessionIdFromCookie; } /* ------------------------------------------------------------ */ /* * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromUrl() */ public boolean isRequestedSessionIdFromUrl() { return _requestedSessionId!=null && !_requestedSessionIdFromCookie; } /* ------------------------------------------------------------ */ /* * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromURL() */ public boolean isRequestedSessionIdFromURL() { return _requestedSessionId!=null && !_requestedSessionIdFromCookie; } /* ------------------------------------------------------------ */ /* * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdValid() */ public boolean isRequestedSessionIdValid() { if (_requestedSessionId==null) return false; HttpSession session=getSession(false); return (session==null?false:_sessionManager.getIdManager().getClusterId(_requestedSessionId).equals(_sessionManager.getClusterId(session))); } /* ------------------------------------------------------------ */ /* * @see javax.servlet.ServletRequest#isSecure() */ public boolean isSecure() { return _connection.isConfidential(this); } /* ------------------------------------------------------------ */ /* * @see javax.servlet.http.HttpServletRequest#isUserInRole(java.lang.String) */ public boolean isUserInRole(String role) { if (_roleMap!=null) { String r=(String)_roleMap.get(role); if (r!=null) role=r; } Principal principal = getUserPrincipal(); if (_userRealm!=null && principal!=null) return _userRealm.isUserInRole(principal, role); return false; } /* ------------------------------------------------------------ */ /* * @see javax.servlet.ServletRequest#removeAttribute(java.lang.String) */ public void removeAttribute(String name) { Object old_value=_attributes==null?null:_attributes.getAttribute(name); if (_attributes!=null) _attributes.removeAttribute(name); if (old_value!=null) { if (_requestAttributeListeners!=null) { final ServletRequestAttributeEvent event = new ServletRequestAttributeEvent(_context,this,name, old_value); final int size=LazyList.size(_requestAttributeListeners); for(int i=0;i<size;i++) { final EventListener listener = (ServletRequestAttributeListener)LazyList.get(_requestAttributeListeners,i); if (listener instanceof ServletRequestAttributeListener) { final ServletRequestAttributeListener l = (ServletRequestAttributeListener)listener; ((ServletRequestAttributeListener)l).attributeRemoved(event); } } } } } /* ------------------------------------------------------------ */ /* * Set a request attribute. * if the attribute name is "org.mortbay.jetty.Request.queryEncoding" then * the value is also passed in a call to {@link #setQueryEncoding}. * * if the attribute name is "org.mortbay.jetty.ResponseBuffer", then * the response buffer is flushed with @{link #flushResponseBuffer} * * @see javax.servlet.ServletRequest#setAttribute(java.lang.String, java.lang.Object) */ public void setAttribute(String name, Object value) { Object old_value=_attributes==null?null:_attributes.getAttribute(name); if ("org.mortbay.jetty.Request.queryEncoding".equals(name)) setQueryEncoding(value==null?null:value.toString()); else if("org.mortbay.jetty.ResponseBuffer".equals(name)) { try { ByteBuffer byteBuffer=(ByteBuffer)value; synchronized (byteBuffer) { NIOBuffer buffer = byteBuffer.isDirect() ?(NIOBuffer)new DirectNIOBuffer(byteBuffer,true) :(NIOBuffer)new IndirectNIOBuffer(byteBuffer,true); ((HttpConnection.Output)getServletResponse().getOutputStream()).sendResponse(buffer); } } catch (IOException e) { throw new RuntimeException(e); } } if (_attributes==null) _attributes=new AttributesMap(); _attributes.setAttribute(name, value); if (_requestAttributeListeners!=null) { final ServletRequestAttributeEvent event = new ServletRequestAttributeEvent(_context,this,name, old_value==null?value:old_value); final int size=LazyList.size(_requestAttributeListeners); for(int i=0;i<size;i++) { final EventListener listener = (ServletRequestAttributeListener)LazyList.get(_requestAttributeListeners,i); if (listener instanceof ServletRequestAttributeListener) { final ServletRequestAttributeListener l = (ServletRequestAttributeListener)listener; if (old_value==null) l.attributeAdded(event); else if (value==null) l.attributeRemoved(event); else l.attributeReplaced(event); } } } } /* ------------------------------------------------------------ */ /* * @see javax.servlet.ServletRequest#setCharacterEncoding(java.lang.String) */ public void setCharacterEncoding(String encoding) throws UnsupportedEncodingException { if (_inputState!=__NONE) return; _characterEncoding=encoding; // check encoding is supported if (!StringUtil.isUTF8(encoding)) "".getBytes(encoding); } /* ------------------------------------------------------------ */ /* * @see javax.servlet.ServletRequest#setCharacterEncoding(java.lang.String) */ public void setCharacterEncodingUnchecked(String encoding) { _characterEncoding=encoding; } /* ------------------------------------------------------------ */ /* * Extract Paramters from query string and/or form _content. */ private void extractParameters() { if (_baseParameters == null) _baseParameters = new MultiMap(16); if (_paramsExtracted) { if (_parameters==null) _parameters=_baseParameters; return; } _paramsExtracted = true; // Handle query string if (_uri!=null && _uri.hasQuery()) { if (_queryEncoding==null) _uri.decodeQueryTo(_baseParameters); else { try { _uri.decodeQueryTo(_baseParameters,_queryEncoding); } catch (UnsupportedEncodingException e) { if (Log.isDebugEnabled()) Log.warn(e); else Log.warn(e.toString()); } } } // handle any _content. String encoding = getCharacterEncoding(); String content_type = getContentType(); if (content_type != null && content_type.length() > 0) { content_type = HttpFields.valueParameters(content_type, null); if (MimeTypes.FORM_ENCODED.equalsIgnoreCase(content_type) && (HttpMethods.POST.equals(getMethod()) || HttpMethods.PUT.equals(getMethod()))) { int content_length = getContentLength(); if (content_length != 0) { try { int maxFormContentSize=-1; if (_context!=null) maxFormContentSize=_context.getContextHandler().getMaxFormContentSize(); else { Integer size = (Integer)_connection.getConnector().getServer().getAttribute("org.mortbay.jetty.Request.maxFormContentSize"); if (size!=null) maxFormContentSize =size.intValue(); } if (content_length>maxFormContentSize && maxFormContentSize > 0) { throw new IllegalStateException("Form too large"+content_length+">"+maxFormContentSize); } InputStream in = getInputStream(); // Add form params to query params UrlEncoded.decodeTo(in, _baseParameters, encoding,content_length<0?maxFormContentSize:-1); } catch (IOException e) { if (Log.isDebugEnabled()) Log.warn(e); else Log.warn(e.toString()); } } } } if (_parameters==null) _parameters=_baseParameters; else if (_parameters!=_baseParameters) { // Merge parameters (needed if parameters extracted after a forward). Iterator iter = _baseParameters.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = (Map.Entry)iter.next(); String name=(String)entry.getKey(); Object values=entry.getValue(); for (int i=0;i<LazyList.size(values);i++) _parameters.add(name, LazyList.get(values, i)); } } } /* ------------------------------------------------------------ */ /** * @param host The host to set. */ public void setServerName(String host) { _serverName = host; } /* ------------------------------------------------------------ */ /** * @param port The port to set. */ public void setServerPort(int port) { _port = port; } /* ------------------------------------------------------------ */ /** * @param addr The address to set. */ public void setRemoteAddr(String addr) { _remoteAddr = addr; } /* ------------------------------------------------------------ */ /** * @param host The host to set. */ public void setRemoteHost(String host) { _remoteHost = host; } /* ------------------------------------------------------------ */ /** * @return Returns the uri. */ public HttpURI getUri() { return _uri; } /* ------------------------------------------------------------ */ /** * @param uri The uri to set. */ public void setUri(HttpURI uri) { _uri = uri; } /* ------------------------------------------------------------ */ /** * @return Returns the connection. */ public HttpConnection getConnection() { return _connection; } /* ------------------------------------------------------------ */ /** * @return Returns the inputState. */ public int getInputState() { return _inputState; } /* ------------------------------------------------------------ */ /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -