View Javadoc

1   // ========================================================================
2   // Copyright (c) 2004-2009 Mort Bay Consulting Pty. Ltd.
3   // ------------------------------------------------------------------------
4   // All rights reserved. This program and the accompanying materials
5   // are made available under the terms of the Eclipse Public License v1.0
6   // and Apache License v2.0 which accompanies this distribution.
7   // The Eclipse Public License is available at 
8   // http://www.eclipse.org/legal/epl-v10.html
9   // The Apache License v2.0 is available at
10  // http://www.opensource.org/licenses/apache2.0.php
11  // You may elect to redistribute this code under either of these licenses. 
12  // ========================================================================
13  
14  package org.eclipse.jetty.server;
15  
16  import java.io.BufferedReader;
17  import java.io.IOException;
18  import java.io.InputStream;
19  import java.io.InputStreamReader;
20  import java.io.UnsupportedEncodingException;
21  import java.net.InetAddress;
22  import java.nio.ByteBuffer;
23  import java.security.Principal;
24  import java.util.Collection;
25  import java.util.Collections;
26  import java.util.Enumeration;
27  import java.util.EventListener;
28  import java.util.HashMap;
29  import java.util.Iterator;
30  import java.util.List;
31  import java.util.Locale;
32  import java.util.Map;
33  
34  import javax.servlet.RequestDispatcher;
35  import javax.servlet.ServletContext;
36  import javax.servlet.ServletInputStream;
37  import javax.servlet.ServletRequest;
38  import javax.servlet.ServletRequestAttributeEvent;
39  import javax.servlet.ServletRequestAttributeListener;
40  import javax.servlet.ServletResponse;
41  import javax.servlet.http.Cookie;
42  import javax.servlet.http.HttpServletRequest;
43  import javax.servlet.http.HttpSession;
44  
45  import org.eclipse.jetty.continuation.Continuation;
46  import org.eclipse.jetty.continuation.ContinuationListener;
47  import org.eclipse.jetty.http.HttpCookie;
48  import org.eclipse.jetty.http.HttpFields;
49  import org.eclipse.jetty.http.HttpHeaders;
50  import org.eclipse.jetty.http.HttpMethods;
51  import org.eclipse.jetty.http.HttpParser;
52  import org.eclipse.jetty.http.HttpURI;
53  import org.eclipse.jetty.http.HttpVersions;
54  import org.eclipse.jetty.http.MimeTypes;
55  import org.eclipse.jetty.io.Buffer;
56  import org.eclipse.jetty.io.BufferUtil;
57  import org.eclipse.jetty.io.EndPoint;
58  import org.eclipse.jetty.io.nio.DirectNIOBuffer;
59  import org.eclipse.jetty.io.nio.IndirectNIOBuffer;
60  import org.eclipse.jetty.io.nio.NIOBuffer;
61  import org.eclipse.jetty.server.handler.ContextHandler;
62  import org.eclipse.jetty.server.handler.ContextHandler.Context;
63  import org.eclipse.jetty.util.Attributes;
64  import org.eclipse.jetty.util.AttributesMap;
65  import org.eclipse.jetty.util.LazyList;
66  import org.eclipse.jetty.util.MultiMap;
67  import org.eclipse.jetty.util.StringUtil;
68  import org.eclipse.jetty.util.URIUtil;
69  import org.eclipse.jetty.util.UrlEncoded;
70  import org.eclipse.jetty.util.log.Log;
71  
72  /* ------------------------------------------------------------ */
73  /** Jetty Request.
74   * <p>
75   * Implements {@link javax.servlet.http.HttpServletRequest} from the {@link javax.servlet.http} package.
76   * </p>
77   * <p>
78   * The standard interface of mostly getters,
79   * is extended with setters so that the request is mutable by the handlers that it is
80   * passed to.  This allows the request object to be as lightweight as possible and not
81   * actually implement any significant behaviour. For example<ul>
82   * 
83   * <li>The {@link Request#getContextPath} method will return null, until the requeset has been
84   * passed to a {@link ContextHandler} which matches the {@link Request#getPathInfo} with a context
85   * path and calls {@link Request#setContextPath} as a result.</li>
86   * 
87   * <li>the HTTP session methods
88   * will all return null sessions until such time as a request has been passed to
89   * a {@link org.eclipse.jetty.servlet.SessionHandler} which checks for session cookies
90   * and enables the ability to create new sessions.</li>
91   * 
92   * <li>The {@link Request#getServletPath} method will return null until the request has been
93   * passed to a {@link org.eclipse.jetty.servlet.ServletHandler} and the pathInfo matched
94   * against the servlet URL patterns and {@link Request#setServletPath} called as a result.</li>
95   * </ul>
96   * 
97   * A request instance is created for each {@link HttpConnection} accepted by the server 
98   * and recycled for each HTTP request received via that connection. An effort is made
99   * to avoid reparsing headers and cookies that are likely to be the same for 
100  * requests from the same connection.
101  * 
102  */
103 public class Request implements HttpServletRequest
104 {
105     private static final String __ASYNC_FWD="org.eclipse.asyncfwd";
106     private static final Collection __defaultLocale = Collections.singleton(Locale.getDefault());
107     private static final int __NONE=0, _STREAM=1, __READER=2;
108 
109     /* ------------------------------------------------------------ */
110     public static Request getRequest(HttpServletRequest request)
111     {
112         if (request instanceof Request)
113             return (Request) request;
114 
115         return HttpConnection.getCurrentConnection().getRequest();
116     }
117     protected final AsyncContinuation _async = new AsyncContinuation();
118     private boolean _asyncSupported=true;
119     private volatile Attributes _attributes;
120     private Authentication _authentication;
121     private MultiMap<String> _baseParameters;
122     private String _characterEncoding;
123     protected HttpConnection _connection;
124     private ContextHandler.Context _context;
125     private boolean _newContext;
126     private String _contextPath;
127     private CookieCutter _cookies;
128     private boolean _cookiesExtracted=false;
129     private DispatcherType _dispatcherType;
130     private boolean _dns=false;
131     private EndPoint _endp;
132     private boolean _handled =false;
133     private int _inputState=__NONE;
134     private String _method;
135     private MultiMap<String> _parameters;
136     private boolean _paramsExtracted;
137     private String _pathInfo;
138     private int _port;
139     private String _protocol=HttpVersions.HTTP_1_1;
140     private String _queryEncoding;
141     private String _queryString;
142     private BufferedReader _reader;
143     private String _readerEncoding;
144     private String _remoteAddr;
145     private String _remoteHost;
146     private Object _requestAttributeListeners;
147     private String _requestedSessionId;
148     private boolean _requestedSessionIdFromCookie=false;
149     private String _requestURI;
150     private Map<Object,HttpSession> _savedNewSessions;
151     private String _scheme=URIUtil.HTTP;
152     private UserIdentity.Scope _scope;
153     private String _serverName;
154     private String _servletPath;
155     private HttpSession _session;
156     private SessionManager _sessionManager;
157     private long _timeStamp;
158 
159     private Buffer _timeStampBuffer;
160     private HttpURI _uri;
161     
162     /* ------------------------------------------------------------ */
163     public Request()
164     {
165     }
166 
167     /* ------------------------------------------------------------ */
168     public Request(HttpConnection connection)
169     {
170         setConnection(connection);
171     }
172 
173     /* ------------------------------------------------------------ */
174     public void addContinuationListener(ContinuationListener listener)
175     {
176         _async.addContinuationListener(listener);
177     }
178 
179     /* ------------------------------------------------------------ */
180     public void addEventListener(final EventListener listener) 
181     {
182         if (listener instanceof ServletRequestAttributeListener)
183             _requestAttributeListeners= LazyList.add(_requestAttributeListeners, listener);
184         if (listener instanceof ContinuationListener)
185             _async.addContinuationListener((ContinuationListener)listener);
186             
187     }
188 
189     /* ------------------------------------------------------------ */
190     /*
191      * Extract Paramters from query string and/or form _content.
192      */
193     private void extractParameters()
194     {
195         if (_baseParameters == null) 
196             _baseParameters = new MultiMap(16);
197         
198         if (_paramsExtracted) 
199         {
200             if (_parameters==null)
201                 _parameters=_baseParameters;
202             return;
203         }
204         
205         _paramsExtracted = true;
206 
207         // Handle query string
208         if (_uri!=null && _uri.hasQuery())
209         {
210             if (_queryEncoding==null)
211                 _uri.decodeQueryTo(_baseParameters);
212             else
213             {
214                 try
215                 {
216                     _uri.decodeQueryTo(_baseParameters,_queryEncoding);
217 
218                 }
219                 catch (UnsupportedEncodingException e)
220                 {
221                     if (Log.isDebugEnabled())
222                         Log.warn(e);
223                     else
224                         Log.warn(e.toString());
225                 }
226             }
227 
228         }
229 
230         // handle any _content.
231         String encoding = getCharacterEncoding();
232         String content_type = getContentType();
233         if (content_type != null && content_type.length() > 0)
234         {
235             content_type = HttpFields.valueParameters(content_type, null);
236             
237             if (MimeTypes.FORM_ENCODED.equalsIgnoreCase(content_type) &&
238                     (HttpMethods.POST.equals(getMethod()) || HttpMethods.PUT.equals(getMethod())))
239             {
240                 int content_length = getContentLength();
241                 if (content_length != 0)
242                 {
243                     try
244                     {
245                         int maxFormContentSize=-1;
246                         
247                         if (_context!=null)
248                             maxFormContentSize=_context.getContextHandler().getMaxFormContentSize();
249                         else
250                         {
251                             Integer size = (Integer)_connection.getConnector().getServer().getAttribute("org.eclipse.jetty.server.Request.maxFormContentSize");
252                             if (size!=null)
253                                 maxFormContentSize =size.intValue();
254                         }
255                         
256                         if (content_length>maxFormContentSize && maxFormContentSize > 0)
257                         {
258                             throw new IllegalStateException("Form too large"+content_length+">"+maxFormContentSize);
259                         }
260                         InputStream in = getInputStream();
261                        
262                         // Add form params to query params
263                         UrlEncoded.decodeTo(in, _baseParameters, encoding,content_length<0?maxFormContentSize:-1);
264                     }
265                     catch (IOException e)
266                     {
267                         if (Log.isDebugEnabled())
268                             Log.warn(e);
269                         else
270                             Log.warn(e.toString());
271                     }
272                 }
273             }
274         }
275         
276         if (_parameters==null)
277             _parameters=_baseParameters;
278         else if (_parameters!=_baseParameters)
279         {
280             // Merge parameters (needed if parameters extracted after a forward).
281             Iterator iter = _baseParameters.entrySet().iterator();
282             while (iter.hasNext())
283             {
284                 Map.Entry entry = (Map.Entry)iter.next();
285                 String name=(String)entry.getKey();
286                 Object values=entry.getValue();
287                 for (int i=0;i<LazyList.size(values);i++)
288                     _parameters.add(name, LazyList.get(values, i));
289             }
290         }   
291     }
292 
293     /* ------------------------------------------------------------ */
294     public AsyncContext getAsyncContext()
295     {
296         if (_async.isInitial() && !isAsyncStarted())
297             throw new IllegalStateException(_async.getStatusString());
298         return _async;
299     }
300 
301     /* ------------------------------------------------------------ */
302     public AsyncContinuation getAsyncContinuation()
303     {
304         return _async;
305     }
306 
307     /* ------------------------------------------------------------ */
308     /* 
309      * @see javax.servlet.ServletRequest#getAttribute(java.lang.String)
310      */
311     public Object getAttribute(String name)
312     {
313         Object attr=(_attributes==null)?null:_attributes.getAttribute(name);
314         if (attr==null && Continuation.ATTRIBUTE.equals(name))
315             return _async;
316         return attr;
317     }
318 
319     /* ------------------------------------------------------------ */
320     /* 
321      * @see javax.servlet.ServletRequest#getAttributeNames()
322      */
323     public Enumeration getAttributeNames()
324     {
325         if (_attributes==null)
326             return Collections.enumeration(Collections.EMPTY_LIST);
327         
328         return AttributesMap.getAttributeNamesCopy(_attributes);
329     }
330     
331     /* ------------------------------------------------------------ */
332     /* 
333      */
334     public Attributes getAttributes()
335     {
336         if (_attributes==null)
337             _attributes=new AttributesMap();
338         return _attributes;
339     }
340 
341     /* ------------------------------------------------------------ */
342     /** Get the authentication.
343      * @return the authentication
344      */
345     public Authentication getAuthentication()
346     {
347         return _authentication;
348     }
349 
350     /* ------------------------------------------------------------ */
351     /* 
352      * @see javax.servlet.http.HttpServletRequest#getAuthType()
353      */
354     public String getAuthType()
355     {
356         if (_authentication instanceof Authentication.Deferred)
357             _authentication = ((Authentication.Deferred)_authentication).authenticate();
358         
359         if (_authentication instanceof Authentication.User)
360             return ((Authentication.User)_authentication).getAuthMethod();
361         return null;
362     }
363     
364     /* ------------------------------------------------------------ */
365     /* 
366      * @see javax.servlet.ServletRequest#getCharacterEncoding()
367      */
368     public String getCharacterEncoding()
369     {
370         return _characterEncoding;
371     }
372 
373     /* ------------------------------------------------------------ */
374     /**
375      * @return Returns the connection.
376      */
377     public HttpConnection getConnection()
378     {
379         return _connection;
380     }
381     
382     /* ------------------------------------------------------------ */
383     /* 
384      * @see javax.servlet.ServletRequest#getContentLength()
385      */
386     public int getContentLength()
387     {
388         return (int)_connection.getRequestFields().getLongField(HttpHeaders.CONTENT_LENGTH_BUFFER);
389     }
390 
391     public long getContentRead()
392     {
393         if (_connection==null || _connection.getParser()==null)
394             return -1;
395         
396         return ((HttpParser)_connection.getParser()).getContentRead();
397     }
398 
399     /* ------------------------------------------------------------ */
400     /* 
401      * @see javax.servlet.ServletRequest#getContentType()
402      */
403     public String getContentType()
404     {
405         return _connection.getRequestFields().getStringField(HttpHeaders.CONTENT_TYPE_BUFFER);
406     }
407 
408     /* ------------------------------------------------------------ */
409     /**
410      * @return The current {@link Context context} used for this request, or <code>null</code> if {@link #setContext} has not yet
411      * been called. 
412      */
413     public Context getContext()
414     {
415         return _context;
416     }
417 
418     /* ------------------------------------------------------------ */
419     /* 
420      * @see javax.servlet.http.HttpServletRequest#getContextPath()
421      */
422     public String getContextPath()
423     {
424         return _contextPath;
425     }
426 
427     /* ------------------------------------------------------------ */
428     /* 
429      * @see javax.servlet.http.HttpServletRequest#getCookies()
430      */
431     public Cookie[] getCookies()
432     {
433         if (_cookiesExtracted) 
434             return _cookies==null?null:_cookies.getCookies();
435 
436         _cookiesExtracted = true;
437         
438         Enumeration enm = _connection.getRequestFields().getValues(HttpHeaders.COOKIE_BUFFER);
439         
440         // Handle no cookies
441         if (enm!=null)
442         {
443             if (_cookies==null)
444                 _cookies=new CookieCutter();
445 
446             while (enm.hasMoreElements())
447             {
448                 String c = (String)enm.nextElement();
449                 _cookies.addCookieField(c);
450             }
451         }
452 
453         return _cookies==null?null:_cookies.getCookies();
454     }
455 
456     /* ------------------------------------------------------------ */
457     /* 
458      * @see javax.servlet.http.HttpServletRequest#getDateHeader(java.lang.String)
459      */
460     public long getDateHeader(String name)
461     {
462         return _connection.getRequestFields().getDateField(name);
463     }
464 
465     /* ------------------------------------------------------------ */
466     public DispatcherType getDispatcherType()
467     {
468     	return _dispatcherType;
469     }
470 
471     /* ------------------------------------------------------------ */
472     /* 
473      * @see javax.servlet.http.HttpServletRequest#getHeader(java.lang.String)
474      */
475     public String getHeader(String name)
476     {
477         return _connection.getRequestFields().getStringField(name);
478     }
479 
480     /* ------------------------------------------------------------ */
481     /* 
482      * @see javax.servlet.http.HttpServletRequest#getHeaderNames()
483      */
484     public Enumeration getHeaderNames()
485     {
486         return _connection.getRequestFields().getFieldNames();
487     }
488 
489     /* ------------------------------------------------------------ */
490     /* 
491      * @see javax.servlet.http.HttpServletRequest#getHeaders(java.lang.String)
492      */
493     public Enumeration getHeaders(String name)
494     {
495         Enumeration e = _connection.getRequestFields().getValues(name);
496         if (e==null)
497             return Collections.enumeration(Collections.EMPTY_LIST);
498         return e;
499     }
500 
501     /* ------------------------------------------------------------ */
502     /**
503      * @return Returns the inputState.
504      */
505     public int getInputState()
506     {
507         return _inputState;
508     }
509 
510     /* ------------------------------------------------------------ */
511     /* 
512      * @see javax.servlet.ServletRequest#getInputStream()
513      */
514     public ServletInputStream getInputStream() throws IOException
515     {
516         if (_inputState!=__NONE && _inputState!=_STREAM)
517             throw new IllegalStateException("READER");
518         _inputState=_STREAM;
519         return _connection.getInputStream();
520     }
521 
522     /* ------------------------------------------------------------ */
523     /* 
524      * @see javax.servlet.http.HttpServletRequest#getIntHeader(java.lang.String)
525      */
526     public int getIntHeader(String name)
527     {
528         return (int)_connection.getRequestFields().getLongField(name);
529     }
530 
531     /* ------------------------------------------------------------ */
532     /* 
533      * @see javax.servlet.ServletRequest#getLocalAddr()
534      */
535     public String getLocalAddr()
536     {
537         return _endp==null?null:_endp.getLocalAddr();
538     }
539 
540     /* ------------------------------------------------------------ */
541     /* 
542      * @see javax.servlet.ServletRequest#getLocale()
543      */
544     public Locale getLocale()
545     {
546         Enumeration enm = _connection.getRequestFields().getValues(HttpHeaders.ACCEPT_LANGUAGE, HttpFields.__separators);
547         
548         // handle no locale
549         if (enm == null || !enm.hasMoreElements())
550             return Locale.getDefault();
551         
552         // sort the list in quality order
553         List acceptLanguage = HttpFields.qualityList(enm);
554         if (acceptLanguage.size()==0)
555             return  Locale.getDefault();
556         
557         int size=acceptLanguage.size();
558 
559         if (size>0)
560         {
561             String language = (String)acceptLanguage.get(0);
562             language=HttpFields.valueParameters(language,null);
563             String country = "";
564             int dash = language.indexOf('-');
565             if (dash > -1)
566             {
567                 country = language.substring(dash + 1).trim();
568                 language = language.substring(0,dash).trim();
569             }
570             return new Locale(language,country);
571         }
572         
573         return  Locale.getDefault();
574     }
575 
576     /* ------------------------------------------------------------ */
577     /* 
578      * @see javax.servlet.ServletRequest#getLocales()
579      */
580     public Enumeration getLocales()
581     {
582 
583         Enumeration enm = _connection.getRequestFields().getValues(HttpHeaders.ACCEPT_LANGUAGE, HttpFields.__separators);
584         
585         // handle no locale
586         if (enm == null || !enm.hasMoreElements())
587             return Collections.enumeration(__defaultLocale);
588         
589         // sort the list in quality order
590         List acceptLanguage = HttpFields.qualityList(enm);
591         
592         if (acceptLanguage.size()==0)
593             return
594             Collections.enumeration(__defaultLocale);
595         
596         Object langs = null;
597         int size=acceptLanguage.size();
598         
599         // convert to locals
600         for (int i=0; i<size; i++)
601         {
602             String language = (String)acceptLanguage.get(i);
603             language=HttpFields.valueParameters(language,null);
604             String country = "";
605             int dash = language.indexOf('-');
606             if (dash > -1)
607             {
608                 country = language.substring(dash + 1).trim();
609                 language = language.substring(0,dash).trim();
610             }
611             langs=LazyList.ensureSize(langs,size);
612             langs=LazyList.add(langs,new Locale(language,country));
613         }
614         
615         if (LazyList.size(langs)==0)
616             return Collections.enumeration(__defaultLocale);
617         
618         return Collections.enumeration(LazyList.getList(langs));
619     }
620 
621     /* ------------------------------------------------------------ */
622     /* 
623      * @see javax.servlet.ServletRequest#getLocalName()
624      */
625     public String getLocalName()
626     {
627         if (_dns)
628             return _endp==null?null:_endp.getLocalHost();
629         return _endp==null?null:_endp.getLocalAddr();
630     }
631 
632     /* ------------------------------------------------------------ */
633     /* 
634      * @see javax.servlet.ServletRequest#getLocalPort()
635      */
636     public int getLocalPort()
637     {
638         return _endp==null?0:_endp.getLocalPort();
639     }
640 
641     /* ------------------------------------------------------------ */
642     /* 
643      * @see javax.servlet.http.HttpServletRequest#getMethod()
644      */
645     public String getMethod()
646     {
647         return _method;
648     }
649 
650     /* ------------------------------------------------------------ */
651     /* 
652      * @see javax.servlet.ServletRequest#getParameter(java.lang.String)
653      */
654     public String getParameter(String name)
655     {
656         if (!_paramsExtracted) 
657             extractParameters();
658         return (String) _parameters.getValue(name, 0);
659     }
660 
661     /* ------------------------------------------------------------ */
662     /* 
663      * @see javax.servlet.ServletRequest#getParameterMap()
664      */
665     public Map getParameterMap()
666     {
667         if (!_paramsExtracted) 
668             extractParameters();
669         
670         return Collections.unmodifiableMap(_parameters.toStringArrayMap());
671     }
672 
673     /* ------------------------------------------------------------ */
674     /* 
675      * @see javax.servlet.ServletRequest#getParameterNames()
676      */
677     public Enumeration getParameterNames()
678     {
679         if (!_paramsExtracted) 
680             extractParameters();
681         return Collections.enumeration(_parameters.keySet());
682     }
683 
684     /* ------------------------------------------------------------ */
685     /**
686      * @return Returns the parameters.
687      */
688     public MultiMap getParameters()
689     {
690         return _parameters;
691     }
692 
693     /* ------------------------------------------------------------ */
694     /* 
695      * @see javax.servlet.ServletRequest#getParameterValues(java.lang.String)
696      */
697     public String[] getParameterValues(String name)
698     {
699         if (!_paramsExtracted) 
700             extractParameters();
701         List vals = _parameters.getValues(name);
702         if (vals==null)
703             return null;
704         return (String[])vals.toArray(new String[vals.size()]);
705     }
706 
707     /* ------------------------------------------------------------ */
708     /* 
709      * @see javax.servlet.http.HttpServletRequest#getPathInfo()
710      */
711     public String getPathInfo()
712     {
713         return _pathInfo;
714     }
715 
716     /* ------------------------------------------------------------ */
717     /* 
718      * @see javax.servlet.http.HttpServletRequest#getPathTranslated()
719      */
720     public String getPathTranslated()
721     {
722         if (_pathInfo==null || _context==null)
723             return null;
724         return _context.getRealPath(_pathInfo);
725     }
726 
727     /* ------------------------------------------------------------ */
728     /* 
729      * @see javax.servlet.ServletRequest#getProtocol()
730      */
731     public String getProtocol()
732     {
733         return _protocol;
734     }
735 
736     /* ------------------------------------------------------------ */
737     public String getQueryEncoding()
738     {
739         return _queryEncoding;
740     }
741 
742     /* ------------------------------------------------------------ */
743     /* 
744      * @see javax.servlet.http.HttpServletRequest#getQueryString()
745      */
746     public String getQueryString()
747     {
748         if (_queryString==null && _uri!=null)
749         {
750             if (_queryEncoding==null)
751                 _queryString=_uri.getQuery();
752             else
753                 _queryString=_uri.getQuery(_queryEncoding);
754         }
755         return _queryString;
756     }
757 
758     /* ------------------------------------------------------------ */
759     /* 
760      * @see javax.servlet.ServletRequest#getReader()
761      */
762     public BufferedReader getReader() throws IOException
763     {
764         if (_inputState!=__NONE && _inputState!=__READER)
765             throw new IllegalStateException("STREAMED");
766 
767         if (_inputState==__READER)
768             return _reader;
769         
770         String encoding=getCharacterEncoding();
771         if (encoding==null)
772             encoding=StringUtil.__ISO_8859_1;
773         
774         if (_reader==null || !encoding.equalsIgnoreCase(_readerEncoding))
775         {
776             final ServletInputStream in = getInputStream();
777             _readerEncoding=encoding;
778             _reader=new BufferedReader(new InputStreamReader(in,encoding))
779             {
780                 public void close() throws IOException
781                 {
782                     in.close();
783                 }   
784             };
785         }
786         _inputState=__READER;
787         return _reader;
788     }
789 
790     /* ------------------------------------------------------------ */
791     /* 
792      * @see javax.servlet.ServletRequest#getRealPath(java.lang.String)
793      */
794     public String getRealPath(String path)
795     {
796         if (_context==null)
797             return null;
798         return _context.getRealPath(path);
799     }
800 
801     /* ------------------------------------------------------------ */
802     /* 
803      * @see javax.servlet.ServletRequest#getRemoteAddr()
804      */
805     public String getRemoteAddr()
806     {
807         if (_remoteAddr != null)
808             return _remoteAddr;	
809         return _endp==null?null:_endp.getRemoteAddr();
810     }
811 
812     /* ------------------------------------------------------------ */
813     /* 
814      * @see javax.servlet.ServletRequest#getRemoteHost()
815      */
816     public String getRemoteHost()
817     {
818         if (_dns)
819         {
820             if (_remoteHost != null)
821             {
822                 return _remoteHost;
823             }
824             return _endp==null?null:_endp.getRemoteHost();
825         }
826         return getRemoteAddr();
827     }
828 
829     /* ------------------------------------------------------------ */
830     /* 
831      * @see javax.servlet.ServletRequest#getRemotePort()
832      */
833     public int getRemotePort()
834     {
835         return _endp==null?0:_endp.getRemotePort();
836     }
837 
838     /* ------------------------------------------------------------ */
839     /* 
840      * @see javax.servlet.http.HttpServletRequest#getRemoteUser()
841      */
842     public String getRemoteUser()
843     {
844         Principal p = getUserPrincipal();
845         if (p==null)
846             return null;
847         return p.getName();
848     }
849 
850     /* ------------------------------------------------------------ */
851     /* 
852      * @see javax.servlet.ServletRequest#getRequestDispatcher(java.lang.String)
853      */
854     public RequestDispatcher getRequestDispatcher(String path)
855     {
856         if (path == null || _context==null)
857             return null;
858 
859         // handle relative path
860         if (!path.startsWith("/"))
861         {
862             String relTo=URIUtil.addPaths(_servletPath,_pathInfo);
863             int slash=relTo.lastIndexOf("/");
864             if (slash>1)
865                 relTo=relTo.substring(0,slash+1);
866             else
867                 relTo="/";
868             path=URIUtil.addPaths(relTo,path);
869         }
870     
871         return _context.getRequestDispatcher(path);
872     }
873     
874     /* ------------------------------------------------------------ */
875     /* 
876      * @see javax.servlet.http.HttpServletRequest#getRequestedSessionId()
877      */
878     public String getRequestedSessionId()
879     {
880         return _requestedSessionId;
881     }
882 
883     /* ------------------------------------------------------------ */
884     /* 
885      * @see javax.servlet.http.HttpServletRequest#getRequestURI()
886      */
887     public String getRequestURI()
888     {
889         if (_requestURI==null && _uri!=null)
890             _requestURI=_uri.getPathAndParam();
891         return _requestURI;
892     }
893 
894     /* ------------------------------------------------------------ */
895     /* 
896      * @see javax.servlet.http.HttpServletRequest#getRequestURL()
897      */
898     public StringBuffer getRequestURL()
899     {
900         final StringBuffer url = new StringBuffer(48);
901         synchronized (url)
902         {
903             String scheme = getScheme();
904             int port = getServerPort();
905 
906             url.append(scheme);
907             url.append("://");
908             url.append(getServerName());
909             if (_port>0 && 
910                 ((scheme.equalsIgnoreCase(URIUtil.HTTP) && port != 80) || 
911                  (scheme.equalsIgnoreCase(URIUtil.HTTPS) && port != 443)))
912             {
913                 url.append(':');
914                 url.append(_port);
915             }
916             
917             url.append(getRequestURI());
918             return url;
919         }
920     }
921 
922     /* ------------------------------------------------------------ */
923     public Response getResponse()
924     {
925         return _connection._response;
926     }
927     
928     /* ------------------------------------------------------------ */
929     /**
930      * Reconstructs the URL the client used to make the request. The returned URL contains a
931      * protocol, server name, port number, and, but it does not include a path.
932      * <p>
933      * Because this method returns a <code>StringBuffer</code>, not a string, you can modify the
934      * URL easily, for example, to append path and query parameters.
935      * 
936      * This method is useful for creating redirect messages and for reporting errors.
937      * 
938      * @return "scheme://host:port"
939      */
940     public StringBuilder getRootURL()
941     {
942         StringBuilder url = new StringBuilder(48);
943         String scheme = getScheme();
944         int port = getServerPort();
945 
946         url.append(scheme);
947         url.append("://");
948         url.append(getServerName());
949 
950         if (port > 0 && ((scheme.equalsIgnoreCase("http") && port != 80) || (scheme.equalsIgnoreCase("https") && port != 443)))
951         {
952             url.append(':');
953             url.append(port);
954         }
955         return url;
956     }
957 
958     /* ------------------------------------------------------------ */
959     /* 
960      * @see javax.servlet.ServletRequest#getScheme()
961      */
962     public String getScheme()
963     {
964         return _scheme;
965     }
966 
967     /* ------------------------------------------------------------ */
968     /* 
969      * @see javax.servlet.ServletRequest#getServerName()
970      */
971     public String getServerName()
972     {       
973         // Return already determined host
974         if (_serverName != null) 
975             return _serverName;
976 
977         // Return host from absolute URI
978         _serverName = _uri.getHost();
979         _port = _uri.getPort();
980         if (_serverName != null) 
981             return _serverName;
982 
983         // Return host from header field
984         Buffer hostPort = _connection.getRequestFields().get(HttpHeaders.HOST_BUFFER);
985         if (hostPort!=null)
986         {
987             for (int i=hostPort.length();i-->0;)   
988             {
989                 if (hostPort.peek(hostPort.getIndex()+i)==':')
990                 {
991                     _serverName=BufferUtil.to8859_1_String(hostPort.peek(hostPort.getIndex(), i));
992                     _port=BufferUtil.toInt(hostPort.peek(hostPort.getIndex()+i+1, hostPort.length()-i-1));
993                     return _serverName;
994                 }
995             }
996             if (_serverName==null || _port<0)
997             {
998                 _serverName=BufferUtil.to8859_1_String(hostPort);
999                 _port = 0;
1000             }
1001             
1002             return _serverName;
1003         }
1004 
1005         // Return host from connection
1006         if (_connection != null)
1007         {
1008             _serverName = getLocalName();
1009             _port = getLocalPort();
1010             if (_serverName != null && !StringUtil.ALL_INTERFACES.equals(_serverName)) 
1011                 return _serverName;
1012         }
1013 
1014         // Return the local host
1015         try
1016         {
1017             _serverName = InetAddress.getLocalHost().getHostAddress();
1018         }
1019         catch (java.net.UnknownHostException e)
1020         {
1021             Log.ignore(e);
1022         }
1023         return _serverName;
1024     }
1025 
1026     /* ------------------------------------------------------------ */
1027     /* 
1028      * @see javax.servlet.ServletRequest#getServerPort()
1029      */
1030     public int getServerPort()
1031     {
1032         if (_port<=0)
1033         {
1034             if (_serverName==null)
1035                 getServerName();
1036         
1037             if (_port<=0)
1038             {
1039                 if (_serverName!=null && _uri!=null)
1040                     _port = _uri.getPort();
1041                 else
1042                     _port = _endp==null?0:_endp.getLocalPort();
1043             }
1044         }
1045         
1046         if (_port<=0)
1047         {
1048             if (getScheme().equalsIgnoreCase(URIUtil.HTTPS))
1049                 return 443;
1050             return 80;
1051         }
1052         return _port;
1053     }
1054 
1055     /* ------------------------------------------------------------ */
1056     public ServletContext getServletContext()
1057     {
1058         return _context;
1059     }
1060 
1061     /* ------------------------------------------------------------ */
1062     /* 
1063      */
1064     public String getServletName()
1065     {
1066         if (_scope!=null)
1067             return _scope.getName();
1068         return null;
1069     }
1070 
1071     /* ------------------------------------------------------------ */
1072     /* 
1073      * @see javax.servlet.http.HttpServletRequest#getServletPath()
1074      */
1075     public String getServletPath()
1076     {
1077         if (_servletPath==null)
1078             _servletPath="";
1079         return _servletPath;
1080     }
1081 
1082     /* ------------------------------------------------------------ */
1083     public ServletResponse getServletResponse()
1084     {
1085         return _connection.getResponse();
1086     }
1087 
1088     /* ------------------------------------------------------------ */
1089     /* 
1090      * @see javax.servlet.http.HttpServletRequest#getSession()
1091      */
1092     public HttpSession getSession()
1093     {
1094         return getSession(true);
1095     }
1096 
1097     /* ------------------------------------------------------------ */
1098     /* 
1099      * @see javax.servlet.http.HttpServletRequest#getSession(boolean)
1100      */
1101     public HttpSession getSession(boolean create)
1102     {
1103         if (_sessionManager==null && create)
1104             throw new IllegalStateException("No SessionHandler or SessionManager");
1105         
1106         if (_session != null && _sessionManager!=null && _sessionManager.isValid(_session))
1107             return _session;
1108         
1109         _session=null;
1110         
1111         String id=getRequestedSessionId();
1112         
1113         if (id != null && _sessionManager!=null)
1114         {
1115             _session=_sessionManager.getHttpSession(id);
1116             if (_session == null && !create)
1117                 return null;
1118         }
1119         
1120         if (_session == null && _sessionManager!=null && create )
1121         {
1122             _session=_sessionManager.newHttpSession(this);
1123             HttpCookie cookie=_sessionManager.getSessionCookie(_session,getContextPath(),isSecure());
1124             if (cookie!=null)
1125                 _connection.getResponse().addCookie(cookie);
1126         }
1127         
1128         return _session;
1129     }
1130     
1131 
1132     /* ------------------------------------------------------------ */
1133     /**
1134      * @return Returns the sessionManager.
1135      */
1136     public SessionManager getSessionManager()
1137     {
1138         return _sessionManager;
1139     }
1140     
1141     /* ------------------------------------------------------------ */
1142     /**
1143      * Get Request TimeStamp
1144      * 
1145      * @return The time that the request was received.
1146      */
1147     public long getTimeStamp()
1148     {
1149         return _timeStamp;
1150     }
1151     
1152     /* ------------------------------------------------------------ */
1153     /**
1154      * Get Request TimeStamp
1155      * 
1156      * @return The time that the request was received.
1157      */
1158     public Buffer getTimeStampBuffer()
1159     {
1160         if (_timeStampBuffer == null && _timeStamp > 0)
1161                 _timeStampBuffer = HttpFields.__dateCache.formatBuffer(_timeStamp);
1162         return _timeStampBuffer;
1163     }
1164     
1165     /* ------------------------------------------------------------ */
1166     /**
1167      * @return Returns the uri.
1168      */
1169     public HttpURI getUri()
1170     {
1171         return _uri;
1172     }
1173     
1174     public UserIdentity getUserIdentity()
1175     {
1176         if (_authentication instanceof Authentication.Deferred)
1177             _authentication = ((Authentication.Deferred)_authentication).authenticate();
1178         
1179         if (_authentication instanceof Authentication.User)
1180             return ((Authentication.User)_authentication).getUserIdentity();
1181         return null;
1182     }
1183     
1184     /* ------------------------------------------------------------ */
1185     public UserIdentity.Scope getUserIdentityScope()
1186     {
1187         return _scope;
1188     }
1189     
1190     /* ------------------------------------------------------------ */
1191     /* 
1192      * @see javax.servlet.http.HttpServletRequest#getUserPrincipal()
1193      */
1194     public Principal getUserPrincipal()
1195     {
1196         if (_authentication instanceof Authentication.Deferred)
1197             _authentication = ((Authentication.Deferred)_authentication).authenticate();
1198         
1199         if (_authentication instanceof Authentication.User)
1200         {
1201             UserIdentity user = ((Authentication.User)_authentication).getUserIdentity();
1202             return user.getUserPrincipal();
1203         }
1204         return null;
1205     }
1206     
1207     /* ------------------------------------------------------------ */
1208     public boolean isAsyncStarted()
1209     {
1210         return _async.isAsyncStarted();
1211     }
1212     
1213     /* ------------------------------------------------------------ */
1214     public boolean isAsyncSupported()
1215     {
1216         return _asyncSupported;
1217     }
1218 
1219     /* ------------------------------------------------------------ */
1220     public boolean isHandled()
1221     {
1222         return _handled;
1223     }
1224     
1225     /* ------------------------------------------------------------ */
1226     /* 
1227      * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromCookie()
1228      */
1229     public boolean isRequestedSessionIdFromCookie()
1230     {
1231         return _requestedSessionId!=null && _requestedSessionIdFromCookie;
1232     }
1233     
1234     /* ------------------------------------------------------------ */
1235     /* 
1236      * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromUrl()
1237      */
1238     public boolean isRequestedSessionIdFromUrl()
1239     {
1240         return _requestedSessionId!=null && !_requestedSessionIdFromCookie;
1241     }
1242     
1243     /* ------------------------------------------------------------ */
1244     /* 
1245      * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromURL()
1246      */
1247     public boolean isRequestedSessionIdFromURL()
1248     {
1249         return _requestedSessionId!=null && !_requestedSessionIdFromCookie;
1250     }
1251     
1252     /* ------------------------------------------------------------ */
1253     /* 
1254      * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdValid()
1255      */
1256     public boolean isRequestedSessionIdValid()
1257     {	
1258         if (_requestedSessionId==null)
1259             return false;
1260         
1261         HttpSession session=getSession(false);
1262         return (session != null && _sessionManager.getIdManager().getClusterId(_requestedSessionId).equals(_sessionManager.getClusterId(session)));
1263     }
1264     
1265     /* ------------------------------------------------------------ */
1266     /* 
1267      * @see javax.servlet.ServletRequest#isSecure()
1268      */
1269     public boolean isSecure()
1270     {
1271         return _connection.isConfidential(this);
1272     }
1273     
1274     /* ------------------------------------------------------------ */
1275     /* 
1276      * @see javax.servlet.http.HttpServletRequest#isUserInRole(java.lang.String)
1277      */
1278     public boolean isUserInRole(String role)
1279     {
1280         if (_authentication instanceof Authentication.Deferred)
1281             _authentication = ((Authentication.Deferred)_authentication).authenticate();
1282         
1283         if (_authentication instanceof Authentication.User)
1284             return ((Authentication.User)_authentication).isUserInRole(_scope,role);
1285         return false;
1286     }
1287     
1288     /* ------------------------------------------------------------ */
1289     public HttpSession recoverNewSession(Object key)
1290     {
1291         if (_savedNewSessions==null)
1292             return null;
1293         return _savedNewSessions.get(key);
1294     }
1295     
1296     /* ------------------------------------------------------------ */
1297     protected void recycle()
1298     {
1299         _authentication=Authentication.NOT_CHECKED;
1300     	_async.recycle();
1301         _asyncSupported=true;
1302         _handled=false;
1303         if (_context!=null)
1304             throw new IllegalStateException("Request in context!");
1305         if(_attributes!=null)
1306             _attributes.clearAttributes();
1307         _characterEncoding=null;
1308         if (_cookies!=null)
1309             _cookies.reset();
1310         _cookiesExtracted=false;
1311         _context=null;
1312         _serverName=null;
1313         _method=null;
1314         _pathInfo=null;
1315         _port=0;
1316         _protocol=HttpVersions.HTTP_1_1;
1317         _queryEncoding=null;
1318         _queryString=null;
1319         _requestedSessionId=null;
1320         _requestedSessionIdFromCookie=false;
1321         _session=null;
1322         _requestURI=null;
1323         _scope=null;
1324         _scheme=URIUtil.HTTP;
1325         _servletPath=null;
1326         _timeStamp=0;
1327         _timeStampBuffer=null;
1328         _uri=null;
1329         if (_baseParameters!=null)
1330             _baseParameters.clear();
1331         _parameters=null;
1332         _paramsExtracted=false;
1333         _inputState=__NONE;
1334         
1335         if (_savedNewSessions!=null)
1336             _savedNewSessions.clear();
1337         _savedNewSessions=null;
1338     }
1339     
1340     /* ------------------------------------------------------------ */
1341     /* 
1342      * @see javax.servlet.ServletRequest#removeAttribute(java.lang.String)
1343      */
1344     public void removeAttribute(String name)
1345     {
1346         Object old_value=_attributes==null?null:_attributes.getAttribute(name);
1347         
1348         if (_attributes!=null)
1349             _attributes.removeAttribute(name);
1350         
1351         if (old_value!=null)
1352         {
1353             if (_requestAttributeListeners!=null)
1354             {
1355                 final ServletRequestAttributeEvent event =
1356                     new ServletRequestAttributeEvent(_context,this,name, old_value);
1357                 final int size=LazyList.size(_requestAttributeListeners);
1358                 for(int i=0;i<size;i++)
1359                 {
1360                     final EventListener listener = (ServletRequestAttributeListener)LazyList.get(_requestAttributeListeners,i);
1361                     if (listener instanceof ServletRequestAttributeListener)
1362                     {
1363                         final ServletRequestAttributeListener l = (ServletRequestAttributeListener)listener;
1364                         l.attributeRemoved(event);
1365                     }
1366                 }
1367             }
1368         }
1369     }
1370     
1371     /* ------------------------------------------------------------ */
1372     public void removeEventListener(final EventListener listener) 
1373     {
1374         _requestAttributeListeners= LazyList.remove(_requestAttributeListeners, listener);
1375     }
1376     /* ------------------------------------------------------------ */
1377     public void saveNewSession(Object key,HttpSession session)
1378     {
1379         if (_savedNewSessions==null)
1380             _savedNewSessions=new HashMap<Object,HttpSession>();
1381         _savedNewSessions.put(key,session);
1382     }
1383     /* ------------------------------------------------------------ */
1384     public void setAsyncSupported(boolean supported)
1385     {
1386         _asyncSupported=supported;
1387     }
1388     
1389     /* ------------------------------------------------------------ */
1390     public void setAsyncTimeout(long timeout)
1391     {
1392         _async.setAsyncTimeout(timeout);
1393     }
1394     
1395     /* ------------------------------------------------------------ */
1396     /* 
1397      * Set a request attribute.
1398      * if the attribute name is "org.eclipse.jetty.server.server.Request.queryEncoding" then
1399      * the value is also passed in a call to {@link #setQueryEncoding}.
1400      *
1401      * if the attribute name is "org.eclipse.jetty.server.server.ResponseBuffer", then
1402      * the response buffer is flushed with @{link #flushResponseBuffer}
1403      *
1404      * @see javax.servlet.ServletRequest#setAttribute(java.lang.String, java.lang.Object)
1405      */
1406     public void setAttribute(String name, Object value)
1407     {
1408         Object old_value=_attributes==null?null:_attributes.getAttribute(name);
1409         
1410         if ("org.eclipse.jetty.server.Request.queryEncoding".equals(name))
1411             setQueryEncoding(value==null?null:value.toString());
1412         else if("org.eclipse.jetty.server.sendContent".equals(name))
1413         {
1414             try 
1415             {
1416                 ((HttpConnection.Output)getServletResponse().getOutputStream()).sendContent(value); 
1417             } 
1418             catch (IOException e)
1419             {
1420                 throw new RuntimeException(e);
1421             }
1422         }
1423         else if("org.eclipse.jetty.server.ResponseBuffer".equals(name))
1424         {
1425             try
1426             {
1427                 final ByteBuffer byteBuffer=(ByteBuffer)value;
1428                 synchronized (byteBuffer)
1429                 {
1430                     NIOBuffer buffer = byteBuffer.isDirect()
1431                         ?new DirectNIOBuffer(byteBuffer,true)
1432                         :new IndirectNIOBuffer(byteBuffer,true);
1433                     ((HttpConnection.Output)getServletResponse().getOutputStream()).sendResponse(buffer);
1434                 }
1435             }
1436             catch (IOException e)
1437             {
1438                 throw new RuntimeException(e);
1439             }
1440         }
1441 
1442         if (_attributes==null)
1443             _attributes=new AttributesMap();
1444         _attributes.setAttribute(name, value);
1445         
1446         if (_requestAttributeListeners!=null)
1447         {
1448             final ServletRequestAttributeEvent event =
1449                 new ServletRequestAttributeEvent(_context,this,name, old_value==null?value:old_value);
1450             final int size=LazyList.size(_requestAttributeListeners);
1451             for(int i=0;i<size;i++)
1452             {
1453                 final EventListener listener = (ServletRequestAttributeListener)LazyList.get(_requestAttributeListeners,i);
1454                 if (listener instanceof ServletRequestAttributeListener)
1455                 {
1456                     final ServletRequestAttributeListener l = (ServletRequestAttributeListener)listener;
1457 
1458                     if (old_value==null)
1459                         l.attributeAdded(event);
1460                     else if (value==null)
1461                         l.attributeRemoved(event);
1462                     else
1463                         l.attributeReplaced(event);
1464                 }
1465             }
1466         }
1467     }
1468     
1469     /* ------------------------------------------------------------ */
1470     /* 
1471      */
1472     public void setAttributes(Attributes attributes)
1473     {
1474         _attributes=attributes;
1475     }
1476     
1477     /* ------------------------------------------------------------ */
1478 
1479     
1480     /* ------------------------------------------------------------ */
1481     /** Set the authentication.
1482      * @param authentication the authentication to set
1483      */
1484     public void setAuthentication(Authentication authentication)
1485     {
1486         _authentication = authentication;
1487     }
1488 
1489     /* ------------------------------------------------------------ */
1490     /* 
1491      * @see javax.servlet.ServletRequest#setCharacterEncoding(java.lang.String)
1492      */
1493     public void setCharacterEncoding(String encoding) throws UnsupportedEncodingException
1494     {
1495         if (_inputState!=__NONE) 
1496             return;
1497 
1498         _characterEncoding=encoding;
1499 
1500         // check encoding is supported
1501         if (!StringUtil.isUTF8(encoding))
1502             //noinspection ResultOfMethodCallIgnored
1503             "".getBytes(encoding);
1504     }
1505 
1506     /* ------------------------------------------------------------ */
1507     /* 
1508      * @see javax.servlet.ServletRequest#setCharacterEncoding(java.lang.String)
1509      */
1510     public void setCharacterEncodingUnchecked(String encoding)
1511     {
1512         _characterEncoding=encoding;
1513     }
1514 
1515     /* ------------------------------------------------------------ */
1516     //final so we can safely call this from constructor
1517     protected final void setConnection(HttpConnection connection)
1518     {
1519         _connection=connection;
1520     	_async.setConnection(connection);
1521         _endp=connection.getEndPoint();
1522         _dns=connection.getResolveNames();
1523     }
1524 
1525     /* ------------------------------------------------------------ */
1526     /* 
1527      * @see javax.servlet.ServletRequest#getContentType()
1528      */
1529     public void setContentType(String contentType)
1530     {
1531         _connection.getRequestFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,contentType);
1532         
1533     }
1534 
1535     /* ------------------------------------------------------------ */
1536     /**
1537      * @param context
1538      */
1539     public void setContext(Context context)
1540     {
1541         _newContext=_context!=context;
1542         _context=context;
1543     }
1544     
1545     /* ------------------------------------------------------------ */
1546     /**
1547      * @return True if this is the first call of takeNewContext() since the last {@link #setContext(Context)} call.
1548      */
1549     public boolean takeNewContext()
1550     {
1551         boolean nc=_newContext;
1552         _newContext=false;
1553         return nc;
1554     }
1555     
1556     /* ------------------------------------------------------------ */
1557     /**
1558      * Sets the "context path" for this request
1559      * @see HttpServletRequest#getContextPath
1560      */
1561     public void setContextPath(String contextPath)
1562     {
1563         _contextPath = contextPath;
1564     }
1565 
1566     /* ------------------------------------------------------------ */
1567     /**
1568      * @param cookies The cookies to set.
1569      */
1570     public void setCookies(Cookie[] cookies)
1571     {
1572         if (_cookies==null)
1573             _cookies=new CookieCutter();
1574         _cookies.setCookies(cookies);
1575     }
1576 
1577     /* ------------------------------------------------------------ */
1578     public void setDispatcherType(DispatcherType type)
1579     {
1580     	_dispatcherType=type;
1581     }
1582     
1583     /* ------------------------------------------------------------ */
1584     public void setHandled(boolean h)
1585     {
1586         _handled=h;
1587     }
1588     
1589     /* ------------------------------------------------------------ */
1590     /**
1591      * @param method The method to set.
1592      */
1593     public void setMethod(String method)
1594     {
1595         _method = method;
1596     }
1597 
1598     /* ------------------------------------------------------------ */
1599     /**
1600      * @param parameters The parameters to set.
1601      */
1602     public void setParameters(MultiMap parameters)
1603     {
1604         _parameters= (parameters==null)?_baseParameters:parameters;
1605         if (_paramsExtracted && _parameters==null)
1606             throw new IllegalStateException();
1607     }
1608 
1609     /* ------------------------------------------------------------ */
1610     /**
1611      * @param pathInfo The pathInfo to set.
1612      */
1613     public void setPathInfo(String pathInfo)
1614     {
1615         _pathInfo = pathInfo;
1616     }
1617     
1618     /* ------------------------------------------------------------ */
1619     /**
1620      * @param protocol The protocol to set.
1621      */
1622     public void setProtocol(String protocol)
1623     {
1624         _protocol = protocol;
1625     }
1626 
1627     /* ------------------------------------------------------------ */
1628     /** Set the character encoding used for the query string.
1629      * This call will effect the return of getQueryString and getParamaters.
1630      * It must be called before any geParameter methods.
1631      * 
1632      * The request attribute "org.eclipse.jetty.server.server.Request.queryEncoding"
1633      * may be set as an alternate method of calling setQueryEncoding.
1634      * 
1635      * @param queryEncoding
1636      */
1637     public void setQueryEncoding(String queryEncoding)
1638     {
1639         _queryEncoding=queryEncoding;
1640         _queryString=null;
1641     }
1642     
1643     /* ------------------------------------------------------------ */
1644     /**
1645      * @param queryString The queryString to set.
1646      */
1647     public void setQueryString(String queryString)
1648     {
1649         _queryString = queryString;
1650     }
1651     
1652     /* ------------------------------------------------------------ */
1653     /**
1654      * @param addr The address to set.
1655      */
1656     public void setRemoteAddr(String addr)
1657     {
1658         _remoteAddr = addr;
1659     }
1660 
1661     /* ------------------------------------------------------------ */
1662     /**
1663      * @param host The host to set.
1664      */
1665     public void setRemoteHost(String host)
1666     {
1667         _remoteHost = host;
1668     }
1669 
1670     /* ------------------------------------------------------------ */
1671     /**
1672      * @param requestedSessionId The requestedSessionId to set.
1673      */
1674     public void setRequestedSessionId(String requestedSessionId)
1675     {
1676         _requestedSessionId = requestedSessionId;
1677     }
1678     
1679     /* ------------------------------------------------------------ */
1680     /**
1681      * @param requestedSessionIdCookie The requestedSessionIdCookie to set.
1682      */
1683     public void setRequestedSessionIdFromCookie(boolean requestedSessionIdCookie)
1684     {
1685         _requestedSessionIdFromCookie = requestedSessionIdCookie;
1686     }
1687 
1688     /* ------------------------------------------------------------ */
1689     /**
1690      * @param requestURI The requestURI to set.
1691      */
1692     public void setRequestURI(String requestURI)
1693     {
1694         _requestURI = requestURI;
1695     }
1696 
1697     /* ------------------------------------------------------------ */
1698     /**
1699      * @param scheme The scheme to set.
1700      */
1701     public void setScheme(String scheme)
1702     {
1703         _scheme = scheme;
1704     }
1705 
1706     /* ------------------------------------------------------------ */
1707     /**
1708      * @param host The host to set.
1709      */
1710     public void setServerName(String host)
1711     {
1712         _serverName = host;
1713     }
1714     
1715     /* ------------------------------------------------------------ */
1716     /**
1717      * @param port The port to set.
1718      */
1719     public void setServerPort(int port)
1720     {
1721         _port = port;
1722     }
1723 
1724     /* ------------------------------------------------------------ */
1725     /**
1726      * @param servletPath The servletPath to set.
1727      */
1728     public void setServletPath(String servletPath)
1729     {
1730         _servletPath = servletPath;
1731     }
1732 
1733     /* ------------------------------------------------------------ */
1734     /**
1735      * @param session The session to set.
1736      */
1737     public void setSession(HttpSession session)
1738     {
1739         _session = session;
1740     }
1741 
1742     /* ------------------------------------------------------------ */
1743     /**
1744      * @param sessionManager The sessionManager to set.
1745      */
1746     public void setSessionManager(SessionManager sessionManager)
1747     {
1748         _sessionManager = sessionManager;
1749     }
1750 
1751     /* ------------------------------------------------------------ */
1752     public void setTimeStamp(long ts)
1753     {
1754         _timeStamp = ts;
1755     }
1756 
1757     /* ------------------------------------------------------------ */
1758     /**
1759      * @param uri The uri to set.
1760      */
1761     public void setUri(HttpURI uri)
1762     {
1763         _uri = uri;
1764     }
1765 
1766     /* ------------------------------------------------------------ */
1767     public void setUserIdentityScope(UserIdentity.Scope scope)
1768     {
1769         _scope=scope;
1770     }
1771 
1772     /* ------------------------------------------------------------ */
1773     public AsyncContext startAsync() throws IllegalStateException
1774     {
1775         if (!_asyncSupported)
1776             throw new IllegalStateException("!asyncSupported");
1777         _async.suspend(_context,this,_connection._response);  
1778         return _async;
1779     }
1780 
1781     /* ------------------------------------------------------------ */
1782     public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) throws IllegalStateException
1783     {
1784         if (!_asyncSupported)
1785             throw new IllegalStateException("!asyncSupported");
1786         _async.suspend(_context,servletRequest,servletResponse);
1787         return _async;
1788     }
1789 
1790     /* ------------------------------------------------------------ */
1791     public String toString()
1792     {
1793         return (_handled?"[":"(")+getMethod()+" "+_uri+(_handled?"]@":")@")+hashCode()+" "+super.toString();
1794     }
1795     
1796 }
1797