annotate src/org/eclipse/jetty/server/Response.java @ 1008:b664624a4423

remove BuffersFactory
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 23 Oct 2016 17:43:49 -0600
parents 74b9daf2826c
children 0114d373748e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 // ========================================================================
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 // ------------------------------------------------------------------------
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 // All rights reserved. This program and the accompanying materials
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 // are made available under the terms of the Eclipse Public License v1.0
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 // and Apache License v2.0 which accompanies this distribution.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 // The Eclipse Public License is available at
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 // http://www.eclipse.org/legal/epl-v10.html
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 // The Apache License v2.0 is available at
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 // http://www.opensource.org/licenses/apache2.0.php
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 // You may elect to redistribute this code under either of these licenses.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 // ========================================================================
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 package org.eclipse.jetty.server;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 import java.io.IOException;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 import java.io.PrintWriter;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 import java.util.Collection;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 import java.util.ArrayList;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 import java.util.Collections;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 import java.util.EnumSet;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 import java.util.Enumeration;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 import java.util.Locale;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 import javax.servlet.RequestDispatcher;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 import javax.servlet.ServletOutputStream;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 import javax.servlet.SessionTrackingMode;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 import javax.servlet.http.Cookie;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 import javax.servlet.http.HttpServletResponse;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 import javax.servlet.http.HttpSession;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 import org.eclipse.jetty.http.HttpCookie;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 import org.eclipse.jetty.http.HttpFields;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 import org.eclipse.jetty.http.HttpHeaderValues;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 import org.eclipse.jetty.http.HttpHeaders;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 import org.eclipse.jetty.http.HttpSchemes;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 import org.eclipse.jetty.http.HttpStatus;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 import org.eclipse.jetty.http.HttpURI;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 import org.eclipse.jetty.http.HttpVersions;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 import org.eclipse.jetty.http.MimeTypes;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 import org.eclipse.jetty.io.BufferCache.CachedBuffer;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 import org.eclipse.jetty.server.handler.ContextHandler;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 import org.eclipse.jetty.util.ByteArrayISO8859Writer;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 import org.eclipse.jetty.util.QuotedStringTokenizer;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50 import org.eclipse.jetty.util.StringUtil;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51 import org.eclipse.jetty.util.URIUtil;
820
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 813
diff changeset
52 import org.slf4j.Logger;
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 813
diff changeset
53 import org.slf4j.LoggerFactory;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55 /** Response.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56 * <p>
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
57 * Implements {@link javax.servlet.http.HttpServletResponse} from the <code>javax.servlet.http</code> package.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
58 * </p>
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
59 */
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
60 public final class Response implements HttpServletResponse
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
61 {
820
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 813
diff changeset
62 private static final Logger LOG = LoggerFactory.getLogger(Response.class);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
63
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
64
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
65 public static final int
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
66 NONE=0,
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
67 STREAM=1,
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
68 WRITER=2;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
69
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
70 /**
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
71 * If a header name starts with this string, the header (stripped of the prefix)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
72 * can be set during include using only {@link #setHeader(String, String)} or
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
73 * {@link #addHeader(String, String)}.
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
74 */
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
75 public final static String SET_INCLUDE_HEADER_PREFIX = "org.eclipse.jetty.server.include.";
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
76
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
77 /**
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
78 * If this string is found within the comment of a cookie added with {@link #addCookie(Cookie)}, then the cookie
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
79 * will be set as HTTP ONLY.
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
80 */
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
81 public final static String HTTP_ONLY_COMMENT="__HTTP_ONLY__";
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
82
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
83 private final AbstractHttpConnection _connection;
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
84 private int _status = SC_OK;
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
85 private String _reason;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
86 private Locale _locale;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
87 private String _mimeType;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
88 private CachedBuffer _cachedMimeType;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
89 private String _characterEncoding;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
90 private boolean _explicitEncoding;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
91 private String _contentType;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
92 private volatile int _outputState;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
93 private PrintWriter _writer;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
94
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
95 public Response(AbstractHttpConnection connection)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
96 {
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
97 _connection = connection;
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
98 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
99
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
100
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
101 void recycle()
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
102 {
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
103 _status = SC_OK;
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
104 _reason = null;
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
105 _locale = null;
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
106 _mimeType = null;
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
107 _cachedMimeType = null;
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
108 _characterEncoding = null;
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
109 _explicitEncoding = false;
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
110 _contentType = null;
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
111 _writer = null;
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
112 _outputState = NONE;
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
113 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
114
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
115 public void addCookie(HttpCookie cookie)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
116 {
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
117 _connection._responseFields.addSetCookie(cookie);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
118 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
119
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
120 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
121 public void addCookie(Cookie cookie)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
122 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
123 String comment=cookie.getComment();
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
124 boolean http_only=false;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
125
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
126 if (comment!=null)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
127 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
128 int i=comment.indexOf(HTTP_ONLY_COMMENT);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
129 if (i>=0)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
130 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
131 http_only=true;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
132 comment=comment.replace(HTTP_ONLY_COMMENT,"").trim();
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
133 if (comment.length()==0)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
134 comment=null;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
135 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
136 }
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
137 _connection._responseFields.addSetCookie(cookie.getName(),
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
138 cookie.getValue(),
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
139 cookie.getDomain(),
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
140 cookie.getPath(),
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
141 cookie.getMaxAge(),
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
142 comment,
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
143 cookie.getSecure(),
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
144 http_only || cookie.isHttpOnly(),
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
145 cookie.getVersion());
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
146 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
147
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
148 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
149 public boolean containsHeader(String name)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
150 {
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
151 return _connection._responseFields.containsKey(name);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
152 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
153
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
154 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
155 public String encodeURL(String url)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
156 {
809
09d518d313b7 remove SessionManager
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
157 throw new UnsupportedOperationException();
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
158 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
159
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
160 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
161 public String encodeRedirectURL(String url)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
162 {
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
163 throw new UnsupportedOperationException();
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
164 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
165
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
166 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
167 @Deprecated
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
168 public String encodeUrl(String url)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
169 {
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
170 throw new UnsupportedOperationException();
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
171 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
172
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
173 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
174 @Deprecated
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
175 public String encodeRedirectUrl(String url)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
176 {
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
177 throw new UnsupportedOperationException();
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
178 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
179
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
180 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
181 public void sendError(int code, String message) throws IOException
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
182 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
183 if (isCommitted())
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
184 LOG.warn("Committed before "+code+" "+message);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
185
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
186 resetBuffer();
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
187 _characterEncoding = null;
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
188 setHeader(HttpHeaders.EXPIRES,null);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
189 setHeader(HttpHeaders.LAST_MODIFIED,null);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
190 setHeader(HttpHeaders.CACHE_CONTROL,null);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
191 setHeader(HttpHeaders.CONTENT_TYPE,null);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
192 setHeader(HttpHeaders.CONTENT_LENGTH,null);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
193
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
194 _outputState = NONE;
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
195 setStatus(code,message);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
196
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
197 if (message==null)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
198 message=HttpStatus.getMessage(code);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
199
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
200 // If we are allowed to have a body
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
201 if (code!=SC_NO_CONTENT &&
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
202 code!=SC_NOT_MODIFIED &&
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
203 code!=SC_PARTIAL_CONTENT &&
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
204 code>=SC_OK)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
205 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
206 Request request = _connection.getRequest();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
207
911
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
208 setHeader(HttpHeaders.CACHE_CONTROL, "must-revalidate,no-cache,no-store");
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
209 setContentType(MimeTypes.TEXT_HTML_8859_1);
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
210 ByteArrayISO8859Writer writer= new ByteArrayISO8859Writer(2048);
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
211 if (message != null)
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
212 {
911
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
213 message= StringUtil.replace(message, "&", "&amp;");
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
214 message= StringUtil.replace(message, "<", "&lt;");
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
215 message= StringUtil.replace(message, ">", "&gt;");
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
216 }
911
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
217 String uri= request.getRequestURI();
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
218 if (uri!=null)
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
219 {
911
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
220 uri= StringUtil.replace(uri, "&", "&amp;");
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
221 uri= StringUtil.replace(uri, "<", "&lt;");
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
222 uri= StringUtil.replace(uri, ">", "&gt;");
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
223 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
224
911
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
225 writer.write("<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=ISO-8859-1\"/>\n");
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
226 writer.write("<title>Error ");
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
227 writer.write(Integer.toString(code));
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
228 writer.write(' ');
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
229 if (message==null)
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
230 message=HttpStatus.getMessage(code);
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
231 writer.write(message);
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
232 writer.write("</title>\n</head>\n<body>\n<h2>HTTP ERROR: ");
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
233 writer.write(Integer.toString(code));
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
234 writer.write("</h2>\n<p>Problem accessing ");
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
235 writer.write(uri);
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
236 writer.write(". Reason:\n<pre> ");
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
237 writer.write(message);
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
238 writer.write("</pre>");
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
239 writer.write("</p>\n<hr /><i><small>Powered by Jetty://</small></i>");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
240
911
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
241 for (int i= 0; i < 20; i++)
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
242 writer.write("\n ");
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
243 writer.write("\n</body>\n</html>\n");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
244
911
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
245 writer.flush();
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
246 setContentLength(writer.size());
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
247 writer.writeTo(getOutputStream());
cab5830e1ab0 remove ErrorHandler
Franklin Schmidt <fschmidt@gmail.com>
parents: 887
diff changeset
248 writer.destroy();
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
249 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
250 else if (code!=SC_PARTIAL_CONTENT)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
251 {
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
252 _connection._requestFields.remove(HttpHeaders.CONTENT_TYPE_BUFFER);
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
253 _connection._requestFields.remove(HttpHeaders.CONTENT_LENGTH_BUFFER);
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
254 _characterEncoding = null;
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
255 _mimeType = null;
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
256 _cachedMimeType = null;
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
257 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
258
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
259 complete();
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
260 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
261
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
262 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
263 public void sendError(int sc) throws IOException
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
264 {
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
265 sendError(sc,null);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
266 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
267
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
268 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
269 public void sendRedirect(String location) throws IOException
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
270 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
271 if (location==null)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
272 throw new IllegalArgumentException();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
273
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
274 if (!URIUtil.hasScheme(location))
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
275 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
276 StringBuilder buf = _connection.getRequest().getRootURL();
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
277 if (location.startsWith("/"))
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
278 buf.append(location);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
279 else
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
280 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
281 String path=_connection.getRequest().getRequestURI();
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
282 String parent=(path.endsWith("/"))?path:URIUtil.parentPath(path);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
283 location=URIUtil.addPaths(parent,location);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
284 if(location==null)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
285 throw new IllegalStateException("path cannot be above root");
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
286 if (!location.startsWith("/"))
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
287 buf.append('/');
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
288 buf.append(location);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
289 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
290
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
291 location=buf.toString();
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
292 HttpURI uri = new HttpURI(location);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
293 String path=uri.getDecodedPath();
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
294 String canonical=URIUtil.canonicalPath(path);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
295 if (canonical==null)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
296 throw new IllegalArgumentException();
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
297 if (!canonical.equals(path))
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
298 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
299 buf = _connection.getRequest().getRootURL();
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
300 buf.append(URIUtil.encodePath(canonical));
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
301 String param=uri.getParam();
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
302 if (param!=null)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
303 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
304 buf.append(';');
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
305 buf.append(param);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
306 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
307 String query=uri.getQuery();
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
308 if (query!=null)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
309 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
310 buf.append('?');
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
311 buf.append(query);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
312 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
313 String fragment=uri.getFragment();
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
314 if (fragment!=null)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
315 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
316 buf.append('#');
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
317 buf.append(fragment);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
318 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
319 location=buf.toString();
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
320 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
321 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
322
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
323 resetBuffer();
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
324 setHeader(HttpHeaders.LOCATION,location);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
325 setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
326 complete();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
327
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
328 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
329
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
330 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
331 public void setDateHeader(String name, long date)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
332 {
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
333 _connection._responseFields.putDateField(name, date);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
334 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
335
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
336 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
337 public void addDateHeader(String name, long date)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
338 {
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
339 _connection._responseFields.addDateField(name, date);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
340 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
341
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
342 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
343 public void setHeader(String name, String value)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
344 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
345 if (HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(name))
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
346 setContentType(value);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
347 else
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
348 {
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
349 _connection._responseFields.put(name, value);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
350 if (HttpHeaders.CONTENT_LENGTH.equalsIgnoreCase(name))
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
351 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
352 if (value==null)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
353 _connection._generator.setContentLength(-1);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
354 else
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
355 _connection._generator.setContentLength(Long.parseLong(value));
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
356 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
357 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
358 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
359
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
360
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
361 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
362 public Collection<String> getHeaderNames()
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
363 {
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
364 final HttpFields fields=_connection._responseFields;
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
365 return fields.getFieldNamesCollection();
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
366 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
367
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
368 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
369 public String getHeader(String name)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
370 {
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
371 return _connection._responseFields.getStringField(name);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
372 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
373
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
374 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
375 public Collection<String> getHeaders(String name)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
376 {
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
377 final HttpFields fields=_connection._responseFields;
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
378 Collection<String> i = fields.getValuesCollection(name);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
379 if (i==null)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
380 return Collections.EMPTY_LIST;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
381 return i;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
382 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
383
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
384 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
385 public void addHeader(String name, String value)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
386 {
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
387
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
388 if (HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(name))
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
389 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
390 setContentType(value);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
391 return;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
392 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
393
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
394 _connection._responseFields.add(name, value);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
395 if (HttpHeaders.CONTENT_LENGTH.equalsIgnoreCase(name))
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
396 _connection._generator.setContentLength(Long.parseLong(value));
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
397 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
398
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
399 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
400 public void setIntHeader(String name, int value)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
401 {
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
402 _connection._responseFields.putLongField(name, value);
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
403 if (HttpHeaders.CONTENT_LENGTH.equalsIgnoreCase(name))
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
404 _connection._generator.setContentLength(value);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
405 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
406
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
407 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
408 public void addIntHeader(String name, int value)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
409 {
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
410 _connection._responseFields.addLongField(name, value);
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
411 if (HttpHeaders.CONTENT_LENGTH.equalsIgnoreCase(name))
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
412 _connection._generator.setContentLength(value);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
413 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
414
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
415 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
416 public void setStatus(int sc)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
417 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
418 setStatus(sc,null);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
419 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
420
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
421 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
422 public void setStatus(int sc, String sm)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
423 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
424 if (sc<=0)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
425 throw new IllegalArgumentException();
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
426 _status = sc;
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
427 _reason = sm;
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
428 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
429
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
430 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
431 public String getCharacterEncoding()
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
432 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
433 if (_characterEncoding==null)
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
434 _characterEncoding = StringUtil.__ISO_8859_1;
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
435 return _characterEncoding;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
436 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
437
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
438 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
439 public String getContentType()
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
440 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
441 return _contentType;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
442 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
443
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
444 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
445 public ServletOutputStream getOutputStream() throws IOException
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
446 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
447 if (_outputState!=NONE && _outputState!=STREAM)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
448 throw new IllegalStateException("WRITER");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
449
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
450 ServletOutputStream out = _connection.getOutputStream();
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
451 _outputState = STREAM;
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
452 return out;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
453 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
454
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
455 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
456 public PrintWriter getWriter() throws IOException
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
457 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
458 if (_outputState!=NONE && _outputState!=WRITER)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
459 throw new IllegalStateException("STREAM");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
460
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
461 /* if there is no writer yet */
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
462 if (_writer==null)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
463 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
464 /* get encoding from Content-Type header */
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
465 String encoding = _characterEncoding;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
466
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
467 if (encoding==null)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
468 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
469 /* implementation of educated defaults */
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
470 if(_cachedMimeType != null)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
471 encoding = MimeTypes.getCharsetFromContentType(_cachedMimeType);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
472
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
473 if (encoding==null)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
474 encoding = StringUtil.__ISO_8859_1;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
475
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
476 setCharacterEncoding(encoding);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
477 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
478
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
479 /* construct Writer using correct encoding */
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
480 _writer = _connection.getPrintWriter(encoding);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
481 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
482 _outputState=WRITER;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
483 return _writer;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
484 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
485
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
486 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
487 public void setCharacterEncoding(String encoding)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
488 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
489 if (this._outputState==0 && !isCommitted())
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
490 {
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
491 _explicitEncoding = true;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
492
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
493 if (encoding==null)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
494 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
495 // Clear any encoding.
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
496 if (_characterEncoding!=null)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
497 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
498 _characterEncoding=null;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
499 if (_cachedMimeType!=null)
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
500 _contentType = _cachedMimeType.toString();
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
501 else if (_mimeType!=null)
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
502 _contentType = _mimeType;
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
503 else
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
504 _contentType = null;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
505
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
506 if (_contentType==null)
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
507 _connection._responseFields.remove(HttpHeaders.CONTENT_TYPE_BUFFER);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
508 else
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
509 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
510 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
511 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
512 else
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
513 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
514 // No, so just add this one to the mimetype
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
515 _characterEncoding=encoding;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
516 if (_contentType!=null)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
517 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
518 int i0=_contentType.indexOf(';');
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
519 if (i0<0)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
520 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
521 _contentType=null;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
522 if(_cachedMimeType!=null)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
523 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
524 CachedBuffer content_type = _cachedMimeType.getAssociate(_characterEncoding);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
525 if (content_type!=null)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
526 {
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
527 _contentType = content_type.toString();
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
528 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,content_type);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
529 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
530 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
531
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
532 if (_contentType==null)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
533 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
534 _contentType = _mimeType+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= ");
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
535 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
536 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
537 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
538 else
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
539 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
540 int i1=_contentType.indexOf("charset=",i0);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
541 if (i1<0)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
542 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
543 _contentType = _contentType+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= ");
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
544 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
545 else
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
546 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
547 int i8=i1+8;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
548 int i2=_contentType.indexOf(" ",i8);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
549 if (i2<0)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
550 _contentType=_contentType.substring(0,i8)+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= ");
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
551 else
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
552 _contentType=_contentType.substring(0,i8)+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= ")+_contentType.substring(i2);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
553 }
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
554 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
555 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
556 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
557 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
558 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
559 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
560
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
561 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
562 public void setContentLength(int len)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
563 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
564 // Protect from setting after committed as default handling
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
565 // of a servlet HEAD request ALWAYS sets _content length, even
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
566 // if the getHandling committed the response!
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
567 if (isCommitted())
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
568 return;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
569 _connection._generator.setContentLength(len);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
570 if (len>0)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
571 {
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
572 _connection._responseFields.putLongField(HttpHeaders.CONTENT_LENGTH, len);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
573 if (_connection._generator.isAllContentWritten())
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
574 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
575 if (_outputState==WRITER)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
576 _writer.close();
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
577 else if (_outputState==STREAM)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
578 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
579 try
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
580 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
581 getOutputStream().close();
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
582 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
583 catch(IOException e)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
584 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
585 throw new RuntimeException(e);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
586 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
587 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
588 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
589 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
590 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
591
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
592 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
593 public void setContentType(String contentType)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
594 {
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
595 if (isCommitted())
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
596 return;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
597
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
598 // Yes this method is horribly complex.... but there are lots of special cases and
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
599 // as this method is called on every request, it is worth trying to save string creation.
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
600 //
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
601
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
602 if (contentType==null)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
603 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
604 if (_locale==null)
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
605 _characterEncoding = null;
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
606 _mimeType = null;
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
607 _cachedMimeType = null;
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
608 _contentType=null;
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
609 _connection._responseFields.remove(HttpHeaders.CONTENT_TYPE_BUFFER);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
610 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
611 else
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
612 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
613 // Look for encoding in contentType
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
614 int i0=contentType.indexOf(';');
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
615
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
616 if (i0>0)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
617 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
618 // we have content type parameters
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
619
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
620 // Extract params off mimetype
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
621 _mimeType = contentType.substring(0,i0).trim();
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
622 _cachedMimeType = MimeTypes.CACHE.get(_mimeType);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
623
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
624 // Look for charset
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
625 int i1=contentType.indexOf("charset=",i0+1);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
626 if (i1>=0)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
627 {
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
628 _explicitEncoding = true;
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
629 int i8=i1+8;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
630 int i2 = contentType.indexOf(' ',i8);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
631
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
632 if (_outputState==WRITER)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
633 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
634 // strip the charset and ignore;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
635 if ((i1==i0+1 && i2<0) || (i1==i0+2 && i2<0 && contentType.charAt(i0+1)==' '))
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
636 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
637 if (_cachedMimeType!=null)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
638 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
639 CachedBuffer content_type = _cachedMimeType.getAssociate(_characterEncoding);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
640 if (content_type!=null)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
641 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
642 _contentType=content_type.toString();
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
643 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,content_type);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
644 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
645 else
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
646 {
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
647 _contentType = _mimeType+";charset="+_characterEncoding;
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
648 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
649 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
650 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
651 else
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
652 {
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
653 _contentType = _mimeType+";charset="+_characterEncoding;
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
654 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
655 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
656 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
657 else if (i2<0)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
658 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
659 _contentType=contentType.substring(0,i1)+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= ");
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
660 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
661 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
662 else
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
663 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
664 _contentType=contentType.substring(0,i1)+contentType.substring(i2)+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= ");
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
665 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
666 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
667 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
668 else if ((i1==i0+1 && i2<0) || (i1==i0+2 && i2<0 && contentType.charAt(i0+1)==' '))
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
669 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
670 // The params are just the char encoding
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
671 _cachedMimeType = MimeTypes.CACHE.get(_mimeType);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
672 _characterEncoding = QuotedStringTokenizer.unquote(contentType.substring(i8));
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
673
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
674 if (_cachedMimeType!=null)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
675 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
676 CachedBuffer content_type = _cachedMimeType.getAssociate(_characterEncoding);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
677 if (content_type!=null)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
678 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
679 _contentType=content_type.toString();
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
680 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,content_type);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
681 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
682 else
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
683 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
684 _contentType=contentType;
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
685 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
686 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
687 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
688 else
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
689 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
690 _contentType=contentType;
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
691 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
692 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
693 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
694 else if (i2>0)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
695 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
696 _characterEncoding = QuotedStringTokenizer.unquote(contentType.substring(i8,i2));
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
697 _contentType=contentType;
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
698 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
699 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
700 else
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
701 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
702 _characterEncoding = QuotedStringTokenizer.unquote(contentType.substring(i8));
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
703 _contentType=contentType;
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
704 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
705 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
706 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
707 else // No encoding in the params.
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
708 {
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
709 _cachedMimeType = null;
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
710 _contentType=_characterEncoding==null?contentType:contentType+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= ");
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
711 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
712 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
713 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
714 else // No params at all
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
715 {
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
716 _mimeType = contentType;
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
717 _cachedMimeType = MimeTypes.CACHE.get(_mimeType);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
718
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
719 if (_characterEncoding!=null)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
720 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
721 if (_cachedMimeType!=null)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
722 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
723 CachedBuffer content_type = _cachedMimeType.getAssociate(_characterEncoding);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
724 if (content_type!=null)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
725 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
726 _contentType=content_type.toString();
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
727 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,content_type);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
728 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
729 else
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
730 {
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
731 _contentType = _mimeType+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= ");
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
732 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
733 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
734 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
735 else
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
736 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
737 _contentType=contentType+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= ");
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
738 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
739 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
740 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
741 else if (_cachedMimeType!=null)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
742 {
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
743 _contentType = _cachedMimeType.toString();
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
744 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_cachedMimeType);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
745 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
746 else
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
747 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
748 _contentType=contentType;
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
749 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
750 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
751 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
752 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
753 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
754
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
755 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
756 public void setBufferSize(int size)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
757 {
983
23ec25435b8c simplify AbstractGenerator
Franklin Schmidt <fschmidt@gmail.com>
parents: 982
diff changeset
758 throw new UnsupportedOperationException();
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
759 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
760
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
761 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
762 public int getBufferSize()
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
763 {
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
764 return _connection._generator.getContentBufferSize();
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
765 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
766
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
767 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
768 public void flushBuffer() throws IOException
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
769 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
770 _connection.flushResponse();
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
771 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
772
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
773 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
774 public void reset()
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
775 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
776 resetBuffer();
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
777 fwdReset();
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
778 _status = 200;
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
779 _reason = null;
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
780
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
781 HttpFields response_fields=_connection._responseFields;
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
782
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
783 response_fields.clear();
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
784 String connection=_connection._requestFields.getStringField(HttpHeaders.CONNECTION_BUFFER);
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
785 if (connection!=null)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
786 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
787 String[] values = connection.split(",");
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
788 for (int i=0;values!=null && i<values.length;i++)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
789 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
790 CachedBuffer cb = HttpHeaderValues.CACHE.get(values[0].trim());
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
791
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
792 if (cb!=null)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
793 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
794 switch(cb.getOrdinal())
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
795 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
796 case HttpHeaderValues.CLOSE_ORDINAL:
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
797 response_fields.put(HttpHeaders.CONNECTION_BUFFER,HttpHeaderValues.CLOSE_BUFFER);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
798 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
799
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
800 case HttpHeaderValues.KEEP_ALIVE_ORDINAL:
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
801 if (HttpVersions.HTTP_1_0.equalsIgnoreCase(_connection.getRequest().getProtocol()))
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
802 response_fields.put(HttpHeaders.CONNECTION_BUFFER,HttpHeaderValues.KEEP_ALIVE);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
803 break;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
804 case HttpHeaderValues.TE_ORDINAL:
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
805 response_fields.put(HttpHeaders.CONNECTION_BUFFER,HttpHeaderValues.TE);
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
806 break;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
807 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
808 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
809 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
810 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
811 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
812
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
813
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
814 private void fwdReset()
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
815 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
816 resetBuffer();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
817
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
818 _writer=null;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
819 _outputState=NONE;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
820 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
821
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
822 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
823 public void resetBuffer()
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
824 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
825 if (isCommitted())
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
826 throw new IllegalStateException("Committed");
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
827 _connection._generator.resetBuffer();
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
828 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
829
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
830 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
831 public boolean isCommitted()
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
832 {
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
833 return _connection._generator.isCommitted();
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
834 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
835
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
836
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
837 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
838 public void setLocale(Locale locale)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
839 {
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
840 if (locale == null || isCommitted())
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
841 return;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
842
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
843 _locale = locale;
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
844 _connection._responseFields.put(HttpHeaders.CONTENT_LANGUAGE_BUFFER,locale.toString().replace('_','-'));
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
845 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
846
999
74b9daf2826c simplify Response
Franklin Schmidt <fschmidt@gmail.com>
parents: 991
diff changeset
847 @Override
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
848 public Locale getLocale()
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
849 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
850 if (_locale==null)
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
851 return Locale.getDefault();
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
852 return _locale;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
853 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
854
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
855 /* ------------------------------------------------------------ */
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
856 /**
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
857 * @return The HTTP status code that has been set for this request. This will be <code>200<code>
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
858 * ({@link HttpServletResponse#SC_OK}), unless explicitly set through one of the <code>setStatus</code> methods.
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
859 */
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
860 public int getStatus()
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
861 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
862 return _status;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
863 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
864
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
865 /* ------------------------------------------------------------ */
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
866 /**
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
867 * @return The reason associated with the current {@link #getStatus() status}. This will be <code>null</code>,
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
868 * unless one of the <code>setStatus</code> methods have been called.
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
869 */
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
870 public String getReason()
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
871 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
872 return _reason;
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
873 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
874
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
875 public void complete()
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
876 throws IOException
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
877 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
878 _connection.completeResponse();
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
879 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
880
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
881 /* ------------------------------------------------------------- */
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
882 /**
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
883 * @return the number of bytes actually written in response body
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
884 */
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
885 public long getContentCount()
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
886 {
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
887 if (_connection==null)
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
888 return -1;
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
889 return _connection._generator.getContentWritten();
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
890 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
891
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
892 public HttpFields getHttpFields()
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
893 {
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
894 return _connection._responseFields;
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
895 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
896
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
897 @Override
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
898 public String toString()
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
899 {
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
900 return "HTTP/1.1 "+_status+" "+ (_reason==null?"":_reason) +System.getProperty("line.separator")+
972
5ee36654b383 simplify AbstractHttpConnection
Franklin Schmidt <fschmidt@gmail.com>
parents: 911
diff changeset
901 _connection._responseFields.toString();
813
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
902 }
f8f7cb485c25 remove UserIdentity
Franklin Schmidt <fschmidt@gmail.com>
parents: 809
diff changeset
903
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
904 }