comparison src/org/eclipse/jetty/server/Response.java @ 972:5ee36654b383

simplify AbstractHttpConnection
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 15 Oct 2016 22:42:05 -0600
parents cab5830e1ab0
children d35b0a3a7a4a
comparison
equal deleted inserted replaced
971:f997df37cec1 972:5ee36654b383
80 * will be set as HTTP ONLY. 80 * will be set as HTTP ONLY.
81 */ 81 */
82 public final static String HTTP_ONLY_COMMENT="__HTTP_ONLY__"; 82 public final static String HTTP_ONLY_COMMENT="__HTTP_ONLY__";
83 83
84 84
85 /* ------------------------------------------------------------ */
86 public static Response getResponse(HttpServletResponse response) 85 public static Response getResponse(HttpServletResponse response)
87 { 86 {
88 if (response instanceof Response) 87 if (response instanceof Response)
89 return (Response)response; 88 return (Response)response;
90 89
135 /* 134 /*
136 * @see javax.servlet.http.HttpServletResponse#addCookie(javax.servlet.http.Cookie) 135 * @see javax.servlet.http.HttpServletResponse#addCookie(javax.servlet.http.Cookie)
137 */ 136 */
138 public void addCookie(HttpCookie cookie) 137 public void addCookie(HttpCookie cookie)
139 { 138 {
140 _connection.getResponseFields().addSetCookie(cookie); 139 _connection._responseFields.addSetCookie(cookie);
141 } 140 }
142 141
143 /* ------------------------------------------------------------ */ 142 /* ------------------------------------------------------------ */
144 /* 143 /*
145 * @see javax.servlet.http.HttpServletResponse#addCookie(javax.servlet.http.Cookie) 144 * @see javax.servlet.http.HttpServletResponse#addCookie(javax.servlet.http.Cookie)
158 comment=comment.replace(HTTP_ONLY_COMMENT,"").trim(); 157 comment=comment.replace(HTTP_ONLY_COMMENT,"").trim();
159 if (comment.length()==0) 158 if (comment.length()==0)
160 comment=null; 159 comment=null;
161 } 160 }
162 } 161 }
163 _connection.getResponseFields().addSetCookie(cookie.getName(), 162 _connection._responseFields.addSetCookie(cookie.getName(),
164 cookie.getValue(), 163 cookie.getValue(),
165 cookie.getDomain(), 164 cookie.getDomain(),
166 cookie.getPath(), 165 cookie.getPath(),
167 cookie.getMaxAge(), 166 cookie.getMaxAge(),
168 comment, 167 comment,
175 /* 174 /*
176 * @see javax.servlet.http.HttpServletResponse#containsHeader(java.lang.String) 175 * @see javax.servlet.http.HttpServletResponse#containsHeader(java.lang.String)
177 */ 176 */
178 public boolean containsHeader(String name) 177 public boolean containsHeader(String name)
179 { 178 {
180 return _connection.getResponseFields().containsKey(name); 179 return _connection._responseFields.containsKey(name);
181 } 180 }
182 181
183 /* ------------------------------------------------------------ */ 182 /* ------------------------------------------------------------ */
184 /* 183 /*
185 * @see javax.servlet.http.HttpServletResponse#encodeURL(java.lang.String) 184 * @see javax.servlet.http.HttpServletResponse#encodeURL(java.lang.String)
216 /* 215 /*
217 * @see javax.servlet.http.HttpServletResponse#sendError(int, java.lang.String) 216 * @see javax.servlet.http.HttpServletResponse#sendError(int, java.lang.String)
218 */ 217 */
219 public void sendError(int code, String message) throws IOException 218 public void sendError(int code, String message) throws IOException
220 { 219 {
221 if (_connection.isIncluding())
222 return;
223
224 if (isCommitted()) 220 if (isCommitted())
225 LOG.warn("Committed before "+code+" "+message); 221 LOG.warn("Committed before "+code+" "+message);
226 222
227 resetBuffer(); 223 resetBuffer();
228 _characterEncoding=null; 224 _characterEncoding=null;
288 writer.writeTo(getOutputStream()); 284 writer.writeTo(getOutputStream());
289 writer.destroy(); 285 writer.destroy();
290 } 286 }
291 else if (code!=SC_PARTIAL_CONTENT) 287 else if (code!=SC_PARTIAL_CONTENT)
292 { 288 {
293 _connection.getRequestFields().remove(HttpHeaders.CONTENT_TYPE_BUFFER); 289 _connection._requestFields.remove(HttpHeaders.CONTENT_TYPE_BUFFER);
294 _connection.getRequestFields().remove(HttpHeaders.CONTENT_LENGTH_BUFFER); 290 _connection._requestFields.remove(HttpHeaders.CONTENT_LENGTH_BUFFER);
295 _characterEncoding=null; 291 _characterEncoding=null;
296 _mimeType=null; 292 _mimeType=null;
297 _cachedMimeType=null; 293 _cachedMimeType=null;
298 } 294 }
299 295
321 * @see javax.servlet.http.HttpServletResponse#sendError(int) 317 * @see javax.servlet.http.HttpServletResponse#sendError(int)
322 */ 318 */
323 public void sendProcessing() throws IOException 319 public void sendProcessing() throws IOException
324 { 320 {
325 if (_connection.isExpecting102Processing() && !isCommitted()) 321 if (_connection.isExpecting102Processing() && !isCommitted())
326 ((HttpGenerator)_connection.getGenerator()).send1xx(HttpStatus.PROCESSING_102); 322 _connection._generator.send1xx(HttpStatus.PROCESSING_102);
327 } 323 }
328 324
329 /* ------------------------------------------------------------ */ 325 /* ------------------------------------------------------------ */
330 /* 326 /*
331 * @see javax.servlet.http.HttpServletResponse#sendRedirect(java.lang.String) 327 * @see javax.servlet.http.HttpServletResponse#sendRedirect(java.lang.String)
332 */ 328 */
333 public void sendRedirect(String location) throws IOException 329 public void sendRedirect(String location) throws IOException
334 { 330 {
335 if (_connection.isIncluding())
336 return;
337
338 if (location==null) 331 if (location==null)
339 throw new IllegalArgumentException(); 332 throw new IllegalArgumentException();
340 333
341 if (!URIUtil.hasScheme(location)) 334 if (!URIUtil.hasScheme(location))
342 { 335 {
398 /* 391 /*
399 * @see javax.servlet.http.HttpServletResponse#setDateHeader(java.lang.String, long) 392 * @see javax.servlet.http.HttpServletResponse#setDateHeader(java.lang.String, long)
400 */ 393 */
401 public void setDateHeader(String name, long date) 394 public void setDateHeader(String name, long date)
402 { 395 {
403 if (!_connection.isIncluding()) 396 _connection._responseFields.putDateField(name, date);
404 _connection.getResponseFields().putDateField(name, date);
405 } 397 }
406 398
407 /* ------------------------------------------------------------ */ 399 /* ------------------------------------------------------------ */
408 /* 400 /*
409 * @see javax.servlet.http.HttpServletResponse#addDateHeader(java.lang.String, long) 401 * @see javax.servlet.http.HttpServletResponse#addDateHeader(java.lang.String, long)
410 */ 402 */
411 public void addDateHeader(String name, long date) 403 public void addDateHeader(String name, long date)
412 { 404 {
413 if (!_connection.isIncluding()) 405 _connection._responseFields.addDateField(name, date);
414 _connection.getResponseFields().addDateField(name, date);
415 } 406 }
416 407
417 /* ------------------------------------------------------------ */ 408 /* ------------------------------------------------------------ */
418 /* 409 /*
419 * @see javax.servlet.http.HttpServletResponse#setHeader(java.lang.String, java.lang.String) 410 * @see javax.servlet.http.HttpServletResponse#setHeader(java.lang.String, java.lang.String)
422 { 413 {
423 if (HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(name)) 414 if (HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(name))
424 setContentType(value); 415 setContentType(value);
425 else 416 else
426 { 417 {
427 if (_connection.isIncluding()) 418 _connection._responseFields.put(name, value);
428 {
429 if (name.startsWith(SET_INCLUDE_HEADER_PREFIX))
430 name=name.substring(SET_INCLUDE_HEADER_PREFIX.length());
431 else
432 return;
433 }
434 _connection.getResponseFields().put(name, value);
435 if (HttpHeaders.CONTENT_LENGTH.equalsIgnoreCase(name)) 419 if (HttpHeaders.CONTENT_LENGTH.equalsIgnoreCase(name))
436 { 420 {
437 if (value==null) 421 if (value==null)
438 _connection._generator.setContentLength(-1); 422 _connection._generator.setContentLength(-1);
439 else 423 else
444 428
445 429
446 /* ------------------------------------------------------------ */ 430 /* ------------------------------------------------------------ */
447 public Collection<String> getHeaderNames() 431 public Collection<String> getHeaderNames()
448 { 432 {
449 final HttpFields fields=_connection.getResponseFields(); 433 final HttpFields fields=_connection._responseFields;
450 return fields.getFieldNamesCollection(); 434 return fields.getFieldNamesCollection();
451 } 435 }
452 436
453 /* ------------------------------------------------------------ */ 437 /* ------------------------------------------------------------ */
454 /* 438 /*
455 */ 439 */
456 public String getHeader(String name) 440 public String getHeader(String name)
457 { 441 {
458 return _connection.getResponseFields().getStringField(name); 442 return _connection._responseFields.getStringField(name);
459 } 443 }
460 444
461 /* ------------------------------------------------------------ */ 445 /* ------------------------------------------------------------ */
462 /* 446 /*
463 */ 447 */
464 public Collection<String> getHeaders(String name) 448 public Collection<String> getHeaders(String name)
465 { 449 {
466 final HttpFields fields=_connection.getResponseFields(); 450 final HttpFields fields=_connection._responseFields;
467 Collection<String> i = fields.getValuesCollection(name); 451 Collection<String> i = fields.getValuesCollection(name);
468 if (i==null) 452 if (i==null)
469 return Collections.EMPTY_LIST; 453 return Collections.EMPTY_LIST;
470 return i; 454 return i;
471 } 455 }
475 * @see javax.servlet.http.HttpServletResponse#addHeader(java.lang.String, java.lang.String) 459 * @see javax.servlet.http.HttpServletResponse#addHeader(java.lang.String, java.lang.String)
476 */ 460 */
477 public void addHeader(String name, String value) 461 public void addHeader(String name, String value)
478 { 462 {
479 463
480 if (_connection.isIncluding())
481 {
482 if (name.startsWith(SET_INCLUDE_HEADER_PREFIX))
483 name=name.substring(SET_INCLUDE_HEADER_PREFIX.length());
484 else
485 return;
486 }
487
488 if (HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(name)) 464 if (HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(name))
489 { 465 {
490 setContentType(value); 466 setContentType(value);
491 return; 467 return;
492 } 468 }
493 469
494 _connection.getResponseFields().add(name, value); 470 _connection._responseFields.add(name, value);
495 if (HttpHeaders.CONTENT_LENGTH.equalsIgnoreCase(name)) 471 if (HttpHeaders.CONTENT_LENGTH.equalsIgnoreCase(name))
496 _connection._generator.setContentLength(Long.parseLong(value)); 472 _connection._generator.setContentLength(Long.parseLong(value));
497 } 473 }
498 474
499 /* ------------------------------------------------------------ */ 475 /* ------------------------------------------------------------ */
500 /* 476 /*
501 * @see javax.servlet.http.HttpServletResponse#setIntHeader(java.lang.String, int) 477 * @see javax.servlet.http.HttpServletResponse#setIntHeader(java.lang.String, int)
502 */ 478 */
503 public void setIntHeader(String name, int value) 479 public void setIntHeader(String name, int value)
504 { 480 {
505 if (!_connection.isIncluding()) 481 _connection._responseFields.putLongField(name, value);
506 { 482 if (HttpHeaders.CONTENT_LENGTH.equalsIgnoreCase(name))
507 _connection.getResponseFields().putLongField(name, value); 483 _connection._generator.setContentLength(value);
508 if (HttpHeaders.CONTENT_LENGTH.equalsIgnoreCase(name))
509 _connection._generator.setContentLength(value);
510 }
511 } 484 }
512 485
513 /* ------------------------------------------------------------ */ 486 /* ------------------------------------------------------------ */
514 /* 487 /*
515 * @see javax.servlet.http.HttpServletResponse#addIntHeader(java.lang.String, int) 488 * @see javax.servlet.http.HttpServletResponse#addIntHeader(java.lang.String, int)
516 */ 489 */
517 public void addIntHeader(String name, int value) 490 public void addIntHeader(String name, int value)
518 { 491 {
519 if (!_connection.isIncluding()) 492 _connection._responseFields.addLongField(name, value);
520 { 493 if (HttpHeaders.CONTENT_LENGTH.equalsIgnoreCase(name))
521 _connection.getResponseFields().addLongField(name, value); 494 _connection._generator.setContentLength(value);
522 if (HttpHeaders.CONTENT_LENGTH.equalsIgnoreCase(name))
523 _connection._generator.setContentLength(value);
524 }
525 } 495 }
526 496
527 /* ------------------------------------------------------------ */ 497 /* ------------------------------------------------------------ */
528 /* 498 /*
529 * @see javax.servlet.http.HttpServletResponse#setStatus(int) 499 * @see javax.servlet.http.HttpServletResponse#setStatus(int)
539 */ 509 */
540 public void setStatus(int sc, String sm) 510 public void setStatus(int sc, String sm)
541 { 511 {
542 if (sc<=0) 512 if (sc<=0)
543 throw new IllegalArgumentException(); 513 throw new IllegalArgumentException();
544 if (!_connection.isIncluding()) 514 _status=sc;
545 { 515 _reason=sm;
546 _status=sc;
547 _reason=sm;
548 }
549 } 516 }
550 517
551 /* ------------------------------------------------------------ */ 518 /* ------------------------------------------------------------ */
552 /* 519 /*
553 * @see javax.servlet.ServletResponse#getCharacterEncoding() 520 * @see javax.servlet.ServletResponse#getCharacterEncoding()
638 /* 605 /*
639 * @see javax.servlet.ServletResponse#setCharacterEncoding(java.lang.String) 606 * @see javax.servlet.ServletResponse#setCharacterEncoding(java.lang.String)
640 */ 607 */
641 public void setCharacterEncoding(String encoding) 608 public void setCharacterEncoding(String encoding)
642 { 609 {
643 if (_connection.isIncluding())
644 return;
645
646 if (this._outputState==0 && !isCommitted()) 610 if (this._outputState==0 && !isCommitted())
647 { 611 {
648 _explicitEncoding=true; 612 _explicitEncoding=true;
649 613
650 if (encoding==null) 614 if (encoding==null)
659 _contentType=_mimeType; 623 _contentType=_mimeType;
660 else 624 else
661 _contentType=null; 625 _contentType=null;
662 626
663 if (_contentType==null) 627 if (_contentType==null)
664 _connection.getResponseFields().remove(HttpHeaders.CONTENT_TYPE_BUFFER); 628 _connection._responseFields.remove(HttpHeaders.CONTENT_TYPE_BUFFER);
665 else 629 else
666 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); 630 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType);
667 } 631 }
668 } 632 }
669 else 633 else
670 { 634 {
671 // No, so just add this one to the mimetype 635 // No, so just add this one to the mimetype
680 { 644 {
681 CachedBuffer content_type = _cachedMimeType.getAssociate(_characterEncoding); 645 CachedBuffer content_type = _cachedMimeType.getAssociate(_characterEncoding);
682 if (content_type!=null) 646 if (content_type!=null)
683 { 647 {
684 _contentType=content_type.toString(); 648 _contentType=content_type.toString();
685 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,content_type); 649 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,content_type);
686 } 650 }
687 } 651 }
688 652
689 if (_contentType==null) 653 if (_contentType==null)
690 { 654 {
691 _contentType = _mimeType+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= "); 655 _contentType = _mimeType+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= ");
692 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); 656 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType);
693 } 657 }
694 } 658 }
695 else 659 else
696 { 660 {
697 int i1=_contentType.indexOf("charset=",i0); 661 int i1=_contentType.indexOf("charset=",i0);
706 if (i2<0) 670 if (i2<0)
707 _contentType=_contentType.substring(0,i8)+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= "); 671 _contentType=_contentType.substring(0,i8)+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= ");
708 else 672 else
709 _contentType=_contentType.substring(0,i8)+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= ")+_contentType.substring(i2); 673 _contentType=_contentType.substring(0,i8)+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= ")+_contentType.substring(i2);
710 } 674 }
711 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); 675 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType);
712 } 676 }
713 } 677 }
714 } 678 }
715 } 679 }
716 } 680 }
722 public void setContentLength(int len) 686 public void setContentLength(int len)
723 { 687 {
724 // Protect from setting after committed as default handling 688 // Protect from setting after committed as default handling
725 // of a servlet HEAD request ALWAYS sets _content length, even 689 // of a servlet HEAD request ALWAYS sets _content length, even
726 // if the getHandling committed the response! 690 // if the getHandling committed the response!
727 if (isCommitted() || _connection.isIncluding()) 691 if (isCommitted())
728 return; 692 return;
729 _connection._generator.setContentLength(len); 693 _connection._generator.setContentLength(len);
730 if (len>0) 694 if (len>0)
731 { 695 {
732 _connection.getResponseFields().putLongField(HttpHeaders.CONTENT_LENGTH, len); 696 _connection._responseFields.putLongField(HttpHeaders.CONTENT_LENGTH, len);
733 if (_connection._generator.isAllContentWritten()) 697 if (_connection._generator.isAllContentWritten())
734 { 698 {
735 if (_outputState==WRITER) 699 if (_outputState==WRITER)
736 _writer.close(); 700 _writer.close();
737 else if (_outputState==STREAM) 701 else if (_outputState==STREAM)
756 public void setLongContentLength(long len) 720 public void setLongContentLength(long len)
757 { 721 {
758 // Protect from setting after committed as default handling 722 // Protect from setting after committed as default handling
759 // of a servlet HEAD request ALWAYS sets _content length, even 723 // of a servlet HEAD request ALWAYS sets _content length, even
760 // if the getHandling committed the response! 724 // if the getHandling committed the response!
761 if (isCommitted() || _connection.isIncluding()) 725 if (isCommitted())
762 return; 726 return;
763 _connection._generator.setContentLength(len); 727 _connection._generator.setContentLength(len);
764 _connection.getResponseFields().putLongField(HttpHeaders.CONTENT_LENGTH, len); 728 _connection._responseFields.putLongField(HttpHeaders.CONTENT_LENGTH, len);
765 } 729 }
766 730
767 /* ------------------------------------------------------------ */ 731 /* ------------------------------------------------------------ */
768 /* 732 /*
769 * @see javax.servlet.ServletResponse#setContentType(java.lang.String) 733 * @see javax.servlet.ServletResponse#setContentType(java.lang.String)
770 */ 734 */
771 public void setContentType(String contentType) 735 public void setContentType(String contentType)
772 { 736 {
773 if (isCommitted() || _connection.isIncluding()) 737 if (isCommitted())
774 return; 738 return;
775 739
776 // Yes this method is horribly complex.... but there are lots of special cases and 740 // Yes this method is horribly complex.... but there are lots of special cases and
777 // as this method is called on every request, it is worth trying to save string creation. 741 // as this method is called on every request, it is worth trying to save string creation.
778 // 742 //
782 if (_locale==null) 746 if (_locale==null)
783 _characterEncoding=null; 747 _characterEncoding=null;
784 _mimeType=null; 748 _mimeType=null;
785 _cachedMimeType=null; 749 _cachedMimeType=null;
786 _contentType=null; 750 _contentType=null;
787 _connection.getResponseFields().remove(HttpHeaders.CONTENT_TYPE_BUFFER); 751 _connection._responseFields.remove(HttpHeaders.CONTENT_TYPE_BUFFER);
788 } 752 }
789 else 753 else
790 { 754 {
791 // Look for encoding in contentType 755 // Look for encoding in contentType
792 int i0=contentType.indexOf(';'); 756 int i0=contentType.indexOf(';');
816 { 780 {
817 CachedBuffer content_type = _cachedMimeType.getAssociate(_characterEncoding); 781 CachedBuffer content_type = _cachedMimeType.getAssociate(_characterEncoding);
818 if (content_type!=null) 782 if (content_type!=null)
819 { 783 {
820 _contentType=content_type.toString(); 784 _contentType=content_type.toString();
821 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,content_type); 785 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,content_type);
822 } 786 }
823 else 787 else
824 { 788 {
825 _contentType=_mimeType+";charset="+_characterEncoding; 789 _contentType=_mimeType+";charset="+_characterEncoding;
826 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); 790 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType);
827 } 791 }
828 } 792 }
829 else 793 else
830 { 794 {
831 _contentType=_mimeType+";charset="+_characterEncoding; 795 _contentType=_mimeType+";charset="+_characterEncoding;
832 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); 796 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType);
833 } 797 }
834 } 798 }
835 else if (i2<0) 799 else if (i2<0)
836 { 800 {
837 _contentType=contentType.substring(0,i1)+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= "); 801 _contentType=contentType.substring(0,i1)+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= ");
838 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); 802 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType);
839 } 803 }
840 else 804 else
841 { 805 {
842 _contentType=contentType.substring(0,i1)+contentType.substring(i2)+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= "); 806 _contentType=contentType.substring(0,i1)+contentType.substring(i2)+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= ");
843 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); 807 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType);
844 } 808 }
845 } 809 }
846 else if ((i1==i0+1 && i2<0) || (i1==i0+2 && i2<0 && contentType.charAt(i0+1)==' ')) 810 else if ((i1==i0+1 && i2<0) || (i1==i0+2 && i2<0 && contentType.charAt(i0+1)==' '))
847 { 811 {
848 // The params are just the char encoding 812 // The params are just the char encoding
853 { 817 {
854 CachedBuffer content_type = _cachedMimeType.getAssociate(_characterEncoding); 818 CachedBuffer content_type = _cachedMimeType.getAssociate(_characterEncoding);
855 if (content_type!=null) 819 if (content_type!=null)
856 { 820 {
857 _contentType=content_type.toString(); 821 _contentType=content_type.toString();
858 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,content_type); 822 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,content_type);
859 } 823 }
860 else 824 else
861 { 825 {
862 _contentType=contentType; 826 _contentType=contentType;
863 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); 827 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType);
864 } 828 }
865 } 829 }
866 else 830 else
867 { 831 {
868 _contentType=contentType; 832 _contentType=contentType;
869 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); 833 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType);
870 } 834 }
871 } 835 }
872 else if (i2>0) 836 else if (i2>0)
873 { 837 {
874 _characterEncoding = QuotedStringTokenizer.unquote(contentType.substring(i8,i2)); 838 _characterEncoding = QuotedStringTokenizer.unquote(contentType.substring(i8,i2));
875 _contentType=contentType; 839 _contentType=contentType;
876 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); 840 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType);
877 } 841 }
878 else 842 else
879 { 843 {
880 _characterEncoding = QuotedStringTokenizer.unquote(contentType.substring(i8)); 844 _characterEncoding = QuotedStringTokenizer.unquote(contentType.substring(i8));
881 _contentType=contentType; 845 _contentType=contentType;
882 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); 846 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType);
883 } 847 }
884 } 848 }
885 else // No encoding in the params. 849 else // No encoding in the params.
886 { 850 {
887 _cachedMimeType=null; 851 _cachedMimeType=null;
888 _contentType=_characterEncoding==null?contentType:contentType+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= "); 852 _contentType=_characterEncoding==null?contentType:contentType+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= ");
889 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); 853 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType);
890 } 854 }
891 } 855 }
892 else // No params at all 856 else // No params at all
893 { 857 {
894 _mimeType=contentType; 858 _mimeType=contentType;
900 { 864 {
901 CachedBuffer content_type = _cachedMimeType.getAssociate(_characterEncoding); 865 CachedBuffer content_type = _cachedMimeType.getAssociate(_characterEncoding);
902 if (content_type!=null) 866 if (content_type!=null)
903 { 867 {
904 _contentType=content_type.toString(); 868 _contentType=content_type.toString();
905 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,content_type); 869 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,content_type);
906 } 870 }
907 else 871 else
908 { 872 {
909 _contentType=_mimeType+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= "); 873 _contentType=_mimeType+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= ");
910 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); 874 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType);
911 } 875 }
912 } 876 }
913 else 877 else
914 { 878 {
915 _contentType=contentType+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= "); 879 _contentType=contentType+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= ");
916 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); 880 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType);
917 } 881 }
918 } 882 }
919 else if (_cachedMimeType!=null) 883 else if (_cachedMimeType!=null)
920 { 884 {
921 _contentType=_cachedMimeType.toString(); 885 _contentType=_cachedMimeType.toString();
922 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_cachedMimeType); 886 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_cachedMimeType);
923 } 887 }
924 else 888 else
925 { 889 {
926 _contentType=contentType; 890 _contentType=contentType;
927 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); 891 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType);
928 } 892 }
929 } 893 }
930 } 894 }
931 } 895 }
932 896
936 */ 900 */
937 public void setBufferSize(int size) 901 public void setBufferSize(int size)
938 { 902 {
939 if (isCommitted() || getContentCount()>0) 903 if (isCommitted() || getContentCount()>0)
940 throw new IllegalStateException("Committed or content written"); 904 throw new IllegalStateException("Committed or content written");
941 _connection.getGenerator().increaseContentBufferSize(size); 905 _connection._generator.increaseContentBufferSize(size);
942 } 906 }
943 907
944 /* ------------------------------------------------------------ */ 908 /* ------------------------------------------------------------ */
945 /* 909 /*
946 * @see javax.servlet.ServletResponse#getBufferSize() 910 * @see javax.servlet.ServletResponse#getBufferSize()
947 */ 911 */
948 public int getBufferSize() 912 public int getBufferSize()
949 { 913 {
950 return _connection.getGenerator().getContentBufferSize(); 914 return _connection._generator.getContentBufferSize();
951 } 915 }
952 916
953 /* ------------------------------------------------------------ */ 917 /* ------------------------------------------------------------ */
954 /* 918 /*
955 * @see javax.servlet.ServletResponse#flushBuffer() 919 * @see javax.servlet.ServletResponse#flushBuffer()
968 resetBuffer(); 932 resetBuffer();
969 fwdReset(); 933 fwdReset();
970 _status=200; 934 _status=200;
971 _reason=null; 935 _reason=null;
972 936
973 HttpFields response_fields=_connection.getResponseFields(); 937 HttpFields response_fields=_connection._responseFields;
974 938
975 response_fields.clear(); 939 response_fields.clear();
976 String connection=_connection.getRequestFields().getStringField(HttpHeaders.CONNECTION_BUFFER); 940 String connection=_connection._requestFields.getStringField(HttpHeaders.CONNECTION_BUFFER);
977 if (connection!=null) 941 if (connection!=null)
978 { 942 {
979 String[] values = connection.split(","); 943 String[] values = connection.split(",");
980 for (int i=0;values!=null && i<values.length;i++) 944 for (int i=0;values!=null && i<values.length;i++)
981 { 945 {
1007 { 971 {
1008 if (!preserveCookies) 972 if (!preserveCookies)
1009 reset(); 973 reset();
1010 else 974 else
1011 { 975 {
1012 HttpFields response_fields=_connection.getResponseFields(); 976 HttpFields response_fields=_connection._responseFields;
1013 977
1014 ArrayList<String> cookieValues = new ArrayList<String>(5); 978 ArrayList<String> cookieValues = new ArrayList<String>(5);
1015 Enumeration<String> vals = response_fields.getValues(HttpHeaders.SET_COOKIE); 979 Enumeration<String> vals = response_fields.getValues(HttpHeaders.SET_COOKIE);
1016 while (vals.hasMoreElements()) 980 while (vals.hasMoreElements())
1017 cookieValues.add((String)vals.nextElement()); 981 cookieValues.add((String)vals.nextElement());
1043 */ 1007 */
1044 public void resetBuffer() 1008 public void resetBuffer()
1045 { 1009 {
1046 if (isCommitted()) 1010 if (isCommitted())
1047 throw new IllegalStateException("Committed"); 1011 throw new IllegalStateException("Committed");
1048 _connection.getGenerator().resetBuffer(); 1012 _connection._generator.resetBuffer();
1049 } 1013 }
1050 1014
1051 /* ------------------------------------------------------------ */ 1015 /* ------------------------------------------------------------ */
1052 /* 1016 /*
1053 * @see javax.servlet.ServletResponse#isCommitted() 1017 * @see javax.servlet.ServletResponse#isCommitted()
1054 */ 1018 */
1055 public boolean isCommitted() 1019 public boolean isCommitted()
1056 { 1020 {
1057 return _connection.isResponseCommitted(); 1021 return _connection._generator.isCommitted();
1058 } 1022 }
1059 1023
1060 1024
1061 /* ------------------------------------------------------------ */ 1025 /* ------------------------------------------------------------ */
1062 /* 1026 /*
1063 * @see javax.servlet.ServletResponse#setLocale(java.util.Locale) 1027 * @see javax.servlet.ServletResponse#setLocale(java.util.Locale)
1064 */ 1028 */
1065 public void setLocale(Locale locale) 1029 public void setLocale(Locale locale)
1066 { 1030 {
1067 if (locale == null || isCommitted() ||_connection.isIncluding()) 1031 if (locale == null || isCommitted())
1068 return; 1032 return;
1069 1033
1070 _locale = locale; 1034 _locale = locale;
1071 _connection.getResponseFields().put(HttpHeaders.CONTENT_LANGUAGE_BUFFER,locale.toString().replace('_','-')); 1035 _connection._responseFields.put(HttpHeaders.CONTENT_LANGUAGE_BUFFER,locale.toString().replace('_','-'));
1072 1036
1073 if (_explicitEncoding || _outputState!=0 ) 1037 if (_explicitEncoding || _outputState!=0 )
1074 return; 1038 return;
1075 1039
1076 if (_connection.getRequest().getContext()==null) 1040 if (_connection.getRequest().getContext()==null)
1098 _mimeType=type.substring(0,semi); 1062 _mimeType=type.substring(0,semi);
1099 _contentType= _mimeType += ";charset="+charset; 1063 _contentType= _mimeType += ";charset="+charset;
1100 } 1064 }
1101 1065
1102 _cachedMimeType=MimeTypes.CACHE.get(_mimeType); 1066 _cachedMimeType=MimeTypes.CACHE.get(_mimeType);
1103 _connection.getResponseFields().put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); 1067 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType);
1104 } 1068 }
1105 } 1069 }
1106 } 1070 }
1107 1071
1108 /* ------------------------------------------------------------ */ 1072 /* ------------------------------------------------------------ */
1149 /** 1113 /**
1150 * @return the number of bytes actually written in response body 1114 * @return the number of bytes actually written in response body
1151 */ 1115 */
1152 public long getContentCount() 1116 public long getContentCount()
1153 { 1117 {
1154 if (_connection==null || _connection.getGenerator()==null) 1118 if (_connection==null)
1155 return -1; 1119 return -1;
1156 return _connection.getGenerator().getContentWritten(); 1120 return _connection._generator.getContentWritten();
1157 } 1121 }
1158 1122
1159 /* ------------------------------------------------------------ */ 1123 /* ------------------------------------------------------------ */
1160 public HttpFields getHttpFields() 1124 public HttpFields getHttpFields()
1161 { 1125 {
1162 return _connection.getResponseFields(); 1126 return _connection._responseFields;
1163 } 1127 }
1164 1128
1165 /* ------------------------------------------------------------ */ 1129 /* ------------------------------------------------------------ */
1166 @Override 1130 @Override
1167 public String toString() 1131 public String toString()
1168 { 1132 {
1169 return "HTTP/1.1 "+_status+" "+ (_reason==null?"":_reason) +System.getProperty("line.separator")+ 1133 return "HTTP/1.1 "+_status+" "+ (_reason==null?"":_reason) +System.getProperty("line.separator")+
1170 _connection.getResponseFields().toString(); 1134 _connection._responseFields.toString();
1171 } 1135 }
1172 1136
1173 /* ------------------------------------------------------------ */ 1137 /* ------------------------------------------------------------ */
1174 /* ------------------------------------------------------------ */ 1138 /* ------------------------------------------------------------ */
1175 /* ------------------------------------------------------------ */ 1139 /* ------------------------------------------------------------ */