comparison src/org/eclipse/jetty/server/handler/ResourceHandler.java @ 827:f89abbfb3a8f

remove Resource.getWeakETag()
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 15 Sep 2016 16:21:56 -0600
parents 0048a843297a
children 688c39c50ee3
comparison
equal deleted inserted replaced
826:6ebf86e4d2ca 827:f89abbfb3a8f
67 String[] _welcomeFiles={"index.html"}; 67 String[] _welcomeFiles={"index.html"};
68 MimeTypes _mimeTypes = new MimeTypes(); 68 MimeTypes _mimeTypes = new MimeTypes();
69 ByteArrayBuffer _cacheControl; 69 ByteArrayBuffer _cacheControl;
70 boolean _aliases; 70 boolean _aliases;
71 boolean _directory; 71 boolean _directory;
72 boolean _etags;
73 72
74 /* ------------------------------------------------------------ */ 73 /* ------------------------------------------------------------ */
75 public ResourceHandler() 74 public ResourceHandler()
76 { 75 {
77 76
125 * @param directory true if directories are listed. 124 * @param directory true if directories are listed.
126 */ 125 */
127 public void setDirectoriesListed(boolean directory) 126 public void setDirectoriesListed(boolean directory)
128 { 127 {
129 _directory = directory; 128 _directory = directory;
130 }
131
132 /* ------------------------------------------------------------ */
133 /**
134 * @return True if ETag processing is done
135 */
136 public boolean isEtags()
137 {
138 return _etags;
139 }
140
141 /* ------------------------------------------------------------ */
142 /**
143 * @param etags True if ETag processing is done
144 */
145 public void setEtags(boolean etags)
146 {
147 _etags = etags;
148 } 129 }
149 130
150 /* ------------------------------------------------------------ */ 131 /* ------------------------------------------------------------ */
151 @Override 132 @Override
152 public void doStart() 133 public void doStart()
436 } 417 }
437 } 418 }
438 419
439 // set some headers 420 // set some headers
440 long last_modified=resource.lastModified(); 421 long last_modified=resource.lastModified();
441 String etag=null;
442 if (_etags)
443 {
444 // simple handling of only a single etag
445 String ifnm = request.getHeader(HttpHeaders.IF_NONE_MATCH);
446 etag=resource.getWeakETag();
447 if (ifnm!=null && resource!=null && ifnm.equals(etag))
448 {
449 response.setStatus(HttpStatus.NOT_MODIFIED_304);
450 baseRequest.getResponse().getHttpFields().put(HttpHeaders.ETAG_BUFFER,etag);
451 return;
452 }
453 }
454
455
456 if (last_modified>0) 422 if (last_modified>0)
457 { 423 {
458 long if_modified=request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE); 424 long if_modified=request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE);
459 if (if_modified>0 && last_modified/1000<=if_modified/1000) 425 if (if_modified>0 && last_modified/1000<=if_modified/1000)
460 { 426 {
468 mime=_mimeTypes.getMimeByExtension(request.getPathInfo()); 434 mime=_mimeTypes.getMimeByExtension(request.getPathInfo());
469 435
470 // set the headers 436 // set the headers
471 doResponseHeaders(response,resource,mime!=null?mime.toString():null); 437 doResponseHeaders(response,resource,mime!=null?mime.toString():null);
472 response.setDateHeader(HttpHeaders.LAST_MODIFIED,last_modified); 438 response.setDateHeader(HttpHeaders.LAST_MODIFIED,last_modified);
473 if (_etags)
474 baseRequest.getResponse().getHttpFields().put(HttpHeaders.ETAG_BUFFER,etag);
475 439
476 if(skipContentBody) 440 if(skipContentBody)
477 return; 441 return;
478 // Send the content 442 // Send the content
479 OutputStream out =null; 443 OutputStream out =null;