comparison src/org/eclipse/jetty/server/handler/ResourceHandler.java @ 1031:921c25a05eaa

remove Buffer.asReadOnlyBuffer()
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 03 Nov 2016 02:04:40 -0600
parents 27f3dc761452
children
comparison
equal deleted inserted replaced
1030:80cad9086593 1031:921c25a05eaa
28 import org.eclipse.jetty.http.HttpFields; 28 import org.eclipse.jetty.http.HttpFields;
29 import org.eclipse.jetty.http.HttpHeaders; 29 import org.eclipse.jetty.http.HttpHeaders;
30 import org.eclipse.jetty.http.HttpMethods; 30 import org.eclipse.jetty.http.HttpMethods;
31 import org.eclipse.jetty.http.HttpStatus; 31 import org.eclipse.jetty.http.HttpStatus;
32 import org.eclipse.jetty.http.MimeTypes; 32 import org.eclipse.jetty.http.MimeTypes;
33 import org.eclipse.jetty.io.Buffer;
34 import org.eclipse.jetty.io.ByteArrayBuffer;
35 import org.eclipse.jetty.io.WriterOutputStream; 33 import org.eclipse.jetty.io.WriterOutputStream;
36 import org.eclipse.jetty.server.AbstractHttpConnection; 34 import org.eclipse.jetty.server.AbstractHttpConnection;
37 import javax.servlet.RequestDispatcher; 35 import javax.servlet.RequestDispatcher;
38 import org.eclipse.jetty.server.Request; 36 import org.eclipse.jetty.server.Request;
39 import org.eclipse.jetty.server.Response; 37 import org.eclipse.jetty.server.Response;
61 Resource _baseResource; 59 Resource _baseResource;
62 Resource _defaultStylesheet; 60 Resource _defaultStylesheet;
63 Resource _stylesheet; 61 Resource _stylesheet;
64 String[] _welcomeFiles={"index.html"}; 62 String[] _welcomeFiles={"index.html"};
65 MimeTypes _mimeTypes = new MimeTypes(); 63 MimeTypes _mimeTypes = new MimeTypes();
66 ByteArrayBuffer _cacheControl;
67 boolean _aliases; 64 boolean _aliases;
68 boolean _directory; 65 boolean _directory;
69 66
70 /* ------------------------------------------------------------ */ 67 /* ------------------------------------------------------------ */
71 public ResourceHandler() 68 public ResourceHandler()
229 { 226 {
230 LOG.warn(e.toString()); 227 LOG.warn(e.toString());
231 LOG.debug("",e); 228 LOG.debug("",e);
232 throw new IllegalArgumentException(stylesheet.toString()); 229 throw new IllegalArgumentException(stylesheet.toString());
233 } 230 }
234 }
235
236 /* ------------------------------------------------------------ */
237 /**
238 * @return the cacheControl header to set on all static content.
239 */
240 public String getCacheControl()
241 {
242 return _cacheControl.toString();
243 }
244
245 /* ------------------------------------------------------------ */
246 /**
247 * @param cacheControl the cacheControl header to set on all static content.
248 */
249 public void setCacheControl(String cacheControl)
250 {
251 _cacheControl=cacheControl==null?null:new ByteArrayBuffer(cacheControl);
252 } 231 }
253 232
254 private Resource getResource(Request request) throws MalformedURLException 233 private Resource getResource(Request request) throws MalformedURLException
255 { 234 {
256 String path = request.getPathInfo(); 235 String path = request.getPathInfo();
446 { 425 {
447 HttpFields fields = ((Response)response).getHttpFields(); 426 HttpFields fields = ((Response)response).getHttpFields();
448 427
449 if (length>0) 428 if (length>0)
450 fields.putLongField(HttpHeaders.CONTENT_LENGTH,length); 429 fields.putLongField(HttpHeaders.CONTENT_LENGTH,length);
451
452 if (_cacheControl!=null)
453 fields.put(HttpHeaders.CACHE_CONTROL,_cacheControl.toString());
454 } 430 }
455 else 431 else
456 { 432 {
457 if (length>0) 433 if (length>0)
458 response.setHeader(HttpHeaders.CONTENT_LENGTH,Long.toString(length)); 434 response.setHeader(HttpHeaders.CONTENT_LENGTH,Long.toString(length));
459
460 if (_cacheControl!=null)
461 response.setHeader(HttpHeaders.CACHE_CONTROL,_cacheControl.toString());
462 } 435 }
463 436
464 } 437 }
465 } 438 }