![JAR search and dependency download from the Maven repository](/logo.png)
org.apache.catalina.connector.Response Maven / Gradle / Ivy
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 1997-2016 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Portions Copyright [2019-2023] Payara Foundation and/or affiliates
package org.apache.catalina.connector;
import static org.apache.catalina.util.RequestUtil.createSessionVersionString;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.logging.Logger;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletResponse;
import com.sun.appserv.ProxyHandler;
import java.io.UnsupportedEncodingException;
import java.nio.charset.UnsupportedCharsetException;
import org.apache.catalina.Connector;
import org.apache.catalina.Context;
import org.apache.catalina.LogFacade;
import org.apache.catalina.Globals;
import org.apache.catalina.HttpResponse;
import org.apache.catalina.Session;
import org.apache.catalina.core.StandardContext;
import org.apache.catalina.security.SecurityUtil;
import org.apache.catalina.util.CharsetMapper;
import org.apache.catalina.util.RequestUtil;
import org.glassfish.grizzly.http.util.CharChunk;
import org.glassfish.grizzly.http.util.CookieHeaderGenerator;
import org.glassfish.grizzly.http.util.CookieSerializerUtils;
import org.glassfish.grizzly.http.util.CookieUtils;
import org.glassfish.grizzly.http.util.FastHttpDateFormat;
import org.glassfish.grizzly.http.util.MimeHeaders;
import org.glassfish.grizzly.http.util.UEncoder;
import org.glassfish.web.util.HtmlEntityEncoder;
// START S1AS 6170450
// END S1AS 6170450
/**
* Wrapper object for the Coyote response.
*
* @author Remy Maucherat
* @author Craig R. McClanahan
* @version $Revision: 1.22 $ $Date: 2007/05/05 05:32:43 $
*/
public class Response
implements HttpResponse, HttpServletResponse {
// ------------------------------------------------------ Static variables
private static final Logger log = LogFacade.getLogger();
private static final ResourceBundle rb = log.getResourceBundle();
/**
* Whether or not to enforce scope checking of this object.
*/
private static boolean enforceScope = false;
public static final String HTTP_RESPONSE_DATE_HEADER =
"EEE, dd MMM yyyy HH:mm:ss zzz";
/**
* Descriptive information about this Response implementation.
*/
protected static final String info =
"org.apache.catalina.connector.Response/1.0";
// ----------------------------------------------------------- Constructors
public Response() {
// START OF SJSAS 6231069
outputBuffer = new OutputBuffer();
outputStream = new CoyoteOutputStream(outputBuffer);
writer = createWriter(outputBuffer);
// END OF SJSAS 6231069
urlEncoder.addSafeCharacter('/');
}
// START OF SJSAS 6231069
public Response(boolean chunkingDisabled) {
outputBuffer = new OutputBuffer();
outputStream = new CoyoteOutputStream(outputBuffer);
writer = createWriter(outputBuffer);
urlEncoder.addSafeCharacter('/');
}
// END OF SJSAS 6231069
// ----------------------------------------------------- Instance Variables
// BEGIN S1AS 4878272
private String detailErrorMsg;
// END S1AS 4878272
/**
* The date format we will use for creating date headers.
*/
protected SimpleDateFormat format = null;
/**
* Associated context.
*/
protected Context context = null;
protected boolean upgrade = false;
// ------------------------------------------------------------- Properties
/**
* Set whether or not to enforce scope checking of this object.
*/
public static void setEnforceScope(boolean enforce) {
enforceScope = enforce;
}
/**
* Associated Catalina connector.
*/
protected Connector connector;
/**
* Return the Connector through which this Request was received.
* @return the Connector
*/
@Override
public Connector getConnector() {
return this.connector;
}
/**
* Set the Connector through which this Request was received.
*
* @param connector The new connector
*/
@Override
public void setConnector(Connector connector) {
this.connector = connector;
}
/**
* Coyote response.
*/
protected org.glassfish.grizzly.http.server.Response coyoteResponse;
/**
* Set the Coyote response.
*
* @param coyoteResponse The Coyote response
*/
public void setCoyoteResponse(org.glassfish.grizzly.http.server.Response coyoteResponse) {
this.coyoteResponse = coyoteResponse;
outputBuffer.setCoyoteResponse(this);
}
/**
* Get the Coyote response.
*/
public org.glassfish.grizzly.http.server.Response getCoyoteResponse() {
return coyoteResponse;
}
/**
* Return the Context within which this Request is being processed.
* @return the Context
*/
@Override
public Context getContext() {
/*
* Ideally, we would call CoyoteResponse.setContext() from
* CoyoteAdapter (the same way we call it for CoyoteRequest), and
* have getContext() return this context. However, for backwards
* compatibility with WS 7.0's NSAPIProcessor, which does not call
* CoyoteResponse.setContext(), we must delegate to the getContext()
* method of the linked request object.
*/
return request.getContext();
}
/**
* Set the Context within which this Request is being processed. This
* must be called as soon as the appropriate Context is identified, because
* it identifies the value to be returned by getContextPath()
,
* and thus enables parsing of the request URI.
*
* @param context The newly associated Context
*/
@Override
public void setContext(Context context) {
this.context = context;
}
/**
* The associated output buffer.
*/
// START OF SJSAS 6231069
//protected OutputBuffer outputBuffer = new OutputBuffer();
protected OutputBuffer outputBuffer;
// END OF SJSAS 6231069
/**
* The associated output stream.
*/
// START OF SJSAS 6231069
/*protected CoyoteOutputStream outputStream =
new CoyoteOutputStream(outputBuffer);*/
protected CoyoteOutputStream outputStream;
// END OF SJSAS 6231069
/**
* The associated writer.
*/
// START OF SJSAS 6231069
// protected CoyoteWriter writer = new CoyoteWriter(outputBuffer);
protected CoyoteWriter writer;
// END OF SJSAS 6231069
/**
* The application commit flag.
*/
protected boolean appCommitted = false;
/**
* The included flag.
*/
protected boolean included = false;
/**
* The characterEncoding flag
*/
private boolean isCharacterEncodingSet = false;
/**
* The contextType flag
*/
private boolean isContentTypeSet = false;
/**
* The error flag.
*/
protected boolean error = false;
/**
* Using output stream flag.
*/
protected boolean usingOutputStream = false;
/**
* Using writer flag.
*/
protected boolean usingWriter = false;
/**
* URL encoder.
*/
protected UEncoder urlEncoder = new UEncoder();
/**
* Recyclable buffer to hold the redirect URL.
*/
protected CharChunk redirectURLCC = new CharChunk();
// --------------------------------------------------------- Public Methods
/**
* Release all object references, and initialize instance variables, in
* preparation for reuse of this object.
*/
@Override
public void recycle() {
if (request != null && request.isAsyncStarted()) {
return;
}
context = null;
outputBuffer.recycle();
usingOutputStream = false;
usingWriter = false;
appCommitted = false;
included = false;
error = false;
isContentTypeSet = false;
isCharacterEncodingSet = false;
detailErrorMsg = null;
if (enforceScope) {
if (facade != null) {
facade.clear();
facade = null;
}
if (outputStream != null) {
outputStream.clear();
outputStream = null;
}
if (writer != null) {
writer.clear();
writer = null;
}
} else {
writer.recycle();
}
}
// ------------------------------------------------------- Response Methods
/**
* Return the number of bytes actually written to the output stream.
* @return the number of bytes
*/
@Override
public int getContentCount() {
return outputBuffer.getContentWritten();
}
/**
* Set the application commit flag.
*
* @param appCommitted The new application committed flag value
*/
@Override
public void setAppCommitted(boolean appCommitted) {
this.appCommitted = appCommitted;
}
/**
* Application commit flag accessor.
* @return If the app is committed, suspended or has no content
*/
@Override
public boolean isAppCommitted() {
return this.appCommitted || isCommitted() || isSuspended()
|| getContentLength() > 0
&& getContentCount() >= getContentLength();
}
/**
* Return the "processing inside an include" flag.
* @return included flag
*/
@Override
public boolean getIncluded() {
return included;
}
/**
* Set the "processing inside an include" flag.
*
* @param included true
if we are currently inside a
* RequestDispatcher.include(), else false
*/
@Override
public void setIncluded(boolean included) {
this.included = included;
}
/**
* Return descriptive information about this Response implementation and
* the corresponding version number, in the format
* <description>/<version>
.
* @return information about this Response
*/
@Override
public String getInfo() {
return info;
}
/**
* The request with which this response is associated.
*/
protected Request request = null;
/**
* Return the Request with which this Response is associated.
* @return the Request
*/
@Override
public org.apache.catalina.Request getRequest() {
return this.request;
}
/**
* Set the Request with which this Response is associated.
*
* @param request The new associated request
*/
@Override
public void setRequest(org.apache.catalina.Request request) {
if (request instanceof Request) {
this.request = (Request) request;
}
}
/**
* The facade associated with this response.
*/
protected ResponseFacade facade = null;
/**
* Return the {@link ServletResponse} for which this object
* is the facade.
* @return the HttpServletResponse
*/
@Override
public HttpServletResponse getResponse() {
if (facade == null) {
facade = new ResponseFacade(this);
}
return facade;
}
/**
* Return the output stream associated with this Response.
* @return the output stream
*/
@Override
public OutputStream getStream() {
if (outputStream == null) {
outputStream = new CoyoteOutputStream(outputBuffer);
}
return outputStream;
}
/**
* Set the output stream associated with this Response.
*
* @param stream The new output stream
*/
@Override
public void setStream(OutputStream stream) {
// This method is evil
}
/**
* Set the suspended flag.
*
* @param suspended The new suspended flag value
*/
@Override
public void setSuspended(boolean suspended) {
outputBuffer.setSuspended(suspended);
}
/**
* Suspended flag accessor.
* @return Suspended flag
*/
@Override
public boolean isSuspended() {
return outputBuffer.isSuspended();
}
/**
* Set the error flag.
*/
@Override
public void setError() {
error = true;
}
/**
* Error flag accessor.
*/
@Override
public boolean isError() {
return error;
}
// BEGIN S1AS 4878272
/**
* Sets detail error message.
*
* @param message detail error message
*/
@Override
public void setDetailMessage(String message) {
this.detailErrorMsg = message;
}
/**
* Gets detail error message.
*
* @return the detail error message
*/
@Override
public String getDetailMessage() {
return this.detailErrorMsg;
}
// END S1AS 4878272
/**
* Create and return a ServletOutputStream to write the content
* associated with this Response.
*
* @exception IOException if an input/output error occurs
*/
@Override
public ServletOutputStream createOutputStream() throws IOException {
// Probably useless
if (outputStream == null) {
outputStream = new CoyoteOutputStream(outputBuffer);
}
return outputStream;
}
/**
* Perform whatever actions are required to flush and close the output
* stream or writer, in a single operation.
*
* @exception IOException if an input/output error occurs
*/
@Override
public void finishResponse() throws IOException {
// Writing leftover bytes
try {
outputBuffer.close();
} catch(IOException e) {
;
} catch(Throwable t) {
log(rb.getString(LogFacade.ERROR_DURING_FINISH_RESPONSE), t);
}
}
/**
* Return the content length that was set or calculated for this Response.
* @return the content length
*/
@Override
public int getContentLength() {
return coyoteResponse.getContentLength();
}
/**
* Return the content type that was set or calculated for this response,
* or null
if no content type was set.
* @return the content type
*/
@Override
public String getContentType() {
return coyoteResponse.getContentType();
}
/**
* Return a PrintWriter that can be used to render error messages,
* regardless of whether a stream or writer has already been acquired.
*
* @return Writer which can be used for error reports. If the response is
* not an error report returned using sendError or triggered by an
* unexpected exception thrown during the servlet processing
* (and only in that case), null will be returned if the response stream
* has already been used.
*
* @exception IOException if an input/output error occurs
*/
@Override
public PrintWriter getReporter() throws IOException {
if (outputBuffer.isNew()) {
outputBuffer.checkConverter();
if (writer == null) {
writer = createWriter(outputBuffer);
}
return writer;
} else {
return null;
}
}
// ------------------------------------------------ ServletResponse Methods
/**
* Flush the buffer and commit this response.
*
* @exception IOException if an input/output error occurs
*/
@Override
public void flushBuffer()
throws IOException {
outputBuffer.flush();
}
/**
* Return the actual buffer size used for this Response.
* @return buffer size in bytes
*/
@Override
public int getBufferSize() {
return outputBuffer.getBufferSize();
}
/**
* Return the character encoding used for this Response.
* @return character encoding i.e. UTF-8
*/
@Override
public String getCharacterEncoding() {
return coyoteResponse.getCharacterEncoding();
}
/**
* Overrides the name of the character encoding used in the body
* of the request. This method must be called prior to reading
* request parameters or reading input using getReader().
*
* @param charset String containing the name of the character encoding.
*/
@Override
public void setCharacterEncoding(String charset) {
if (isCommitted())
return;
// Ignore any call from an included servlet
if (included)
return;
// Ignore any call made after the getWriter has been invoked
// The default should be used
if (usingWriter)
return;
coyoteResponse.setCharacterEncoding(charset);
isCharacterEncodingSet = true;
}
/**
* Return the servlet output stream associated with this Response.
*
* @return the servlet output stream
* @exception IllegalStateException if getWriter
has
* already been called for this response
* @exception IOException if an input/output error occurs
*/
@Override
public ServletOutputStream getOutputStream()
throws IOException {
if (usingWriter)
throw new IllegalStateException
(rb.getString(LogFacade.GET_WRITER_BEEN_CALLED_EXCEPTION));
usingOutputStream = true;
if (outputStream == null) {
outputStream = new CoyoteOutputStream(outputBuffer);
}
return outputStream;
}
/**
* Return the Locale assigned to this response.
* @return assigned Locale
*/
@Override
public Locale getLocale() {
return coyoteResponse.getLocale();
}
/**
* Return the writer associated with this Response.
*
* @return associated writer
* @exception IllegalStateException if getOutputStream
has
* already been called for this response
* @exception IOException if an input/output error occurs
*/
@Override
public PrintWriter getWriter() throws IOException {
if (usingOutputStream) {
throw new IllegalStateException(rb.getString(LogFacade.GET_OUTPUT_STREAM_BEEN_CALLED_EXCEPTION));
}
try {
/*
* If the response's character encoding has not been specified as
* described in getCharacterEncoding
(i.e., the method
* just returns the default value ISO-8859-1
),
* getWriter
updates it to ISO-8859-1
* (with the effect that a subsequent call to getContentType() will
* include a charset=ISO-8859-1 component which will also be
* reflected in the Content-Type response header, thereby satisfying
* the Servlet spec requirement that containers must communicate the
* character encoding used for the servlet response's writer to the
* client).
*/
setCharacterEncoding(getCharacterEncoding());
usingWriter = true;
outputBuffer.checkConverter();
if (writer == null) {
writer = createWriter(outputBuffer);
}
} catch (UnsupportedCharsetException uce) {
UnsupportedEncodingException uee
= new UnsupportedEncodingException(uce.getMessage());
uee.initCause(uce);
throw uee;
}
return writer;
}
/**
* Has the output of this response already been committed?
* @return If the response is committed
*/
@Override
public boolean isCommitted() {
return coyoteResponse.isCommitted();
}
/**
* Clear any content written to the buffer.
*
* @exception IllegalStateException if this response has already
* been committed
*/
@Override
public void reset() {
if (included) {
return; // Ignore any call from an included servlet
}
coyoteResponse.reset();
outputBuffer.reset();
// reset Grizzly duplicated internal attributes
coyoteResponse.resetBuffer(true);
usingOutputStream = false;
usingWriter = false;
isCharacterEncodingSet = false;
}
/**
* Reset the data buffer but not any status or header information.
*
* @exception IllegalStateException if the response has already
* been committed
*/
@Override
public void resetBuffer() {
resetBuffer(false);
}
/**
* Reset the data buffer and the using Writer/Stream flags but not any
* status or header information.
*
* @param resetWriterStreamFlags true
if the internal
* usingWriter
, usingOutputStream
,
* isCharacterEncodingSet
flags should also be reset
*
* @exception IllegalStateException if the response has already
* been committed
*/
@Override
public void resetBuffer(boolean resetWriterStreamFlags) {
if (isCommitted())
throw new IllegalStateException(rb.getString(LogFacade.CANNOT_RESET_BUFFER_EXCEPTION));
outputBuffer.reset();
if(resetWriterStreamFlags) {
usingOutputStream = false;
usingWriter = false;
isCharacterEncodingSet = false;
}
}
/**
* Set the buffer size to be used for this Response.
*
* @param size The new buffer size
*
* @exception IllegalStateException if this method is called after
* output has been committed for this response
*/
@Override
public void setBufferSize(int size) {
if (isCommitted() || !outputBuffer.isNew())
throw new IllegalStateException(rb.getString(LogFacade.CANNOT_CHANGE_BUFFER_SIZE_EXCEPTION));
outputBuffer.setBufferSize(size);
}
/**
* Set the content length (in bytes) for this Response.
*
* @param length The new content length
*/
@Override
public void setContentLength(int length) {
setContentLengthLong(length);
}
/**
* Sets the length of the content body in the response In HTTP servlets,
* this method sets the HTTP Content-Length header.
*
* @param length The new content length
*/
@Override
public void setContentLengthLong(long length) {
if (isCommitted())
return;
// Ignore any call from an included servlet
if (included)
return;
if (usingWriter)
return;
coyoteResponse.setContentLengthLong(length);
}
/**
* Set the content type for this Response.
*
* @param type The new content type
*/
@Override
public void setContentType(String type) {
if (isCommitted())
return;
// Ignore any call from an included servlet
if (included)
return;
// Ignore charset if getWriter() has already been called
if (usingWriter) {
if (type != null) {
int index = type.indexOf(';');
if (index != -1) {
type = type.substring(0, index);
}
}
}
coyoteResponse.setContentType(type);
// Check to see if content type contains charset
if (type != null) {
int index = type.indexOf(';');
if (index != -1) {
int len = type.length();
index++;
while (index < len && Character.isWhitespace(type.charAt(index))) {
index++;
}
if (index + 7 < len
&& type.charAt(index) == 'c'
&& type.charAt(index + 1) == 'h'
&& type.charAt(index + 2) == 'a'
&& type.charAt(index + 3) == 'r'
&& type.charAt(index + 4) == 's'
&& type.charAt(index + 5) == 'e'
&& type.charAt(index + 6) == 't'
&& type.charAt(index + 7) == '=') {
isCharacterEncodingSet = true;
}
}
}
isContentTypeSet = true;
}
/**
* Set the Locale that is appropriate for this response, including
* setting the appropriate character encoding.
*
* @param locale The new locale
*/
@Override
public void setLocale(Locale locale) {
if (isCommitted())
return;
// Ignore any call from an included servlet
if (included)
return;
coyoteResponse.setLocale(locale);
// Ignore any call made after the getWriter has been invoked.
// The default should be used
if (usingWriter)
return;
if (isCharacterEncodingSet) {
return;
}
CharsetMapper cm = getContext().getCharsetMapper();
String charset = cm.getCharset( locale );
if ( charset != null ){
coyoteResponse.setCharacterEncoding(charset);
}
}
// --------------------------------------------------- HttpResponse Methods
/**
* Return the value for the specified header, or null
if this
* header has not been set. If more than one value was added for this
* name, only the first is returned; use {@link #getHeaders(String)} to
* retrieve all of them.
*
* @param name Header name to look up
*/
@Override
public String getHeader(String name) {
return coyoteResponse.getHeader(name);
}
/**
* @return a (possibly empty) Collection
of the names
* of the headers of this response
*/
@Override
public Collection getHeaderNames() {
final Collection result = new ArrayList<>();
for (final String headerName : coyoteResponse.getResponse().getHeaders().names()) {
result.add(headerName);
}
return result;
}
/**
* @param name the name of the response header whose values to return
*
* @return a (possibly empty) Collection
of the values
* of the response header with the given name
*/
@Override
public Collection getHeaders(String name) {
final Collection result = new ArrayList<>();
for (final String headerValue : coyoteResponse.getResponse().getHeaders().values(name)) {
result.add(headerValue);
}
return result;
}
/**
* Return the error message that was set with sendError()
* for this Response.
* @return the error message
*/
@Override
public String getMessage() {
return coyoteResponse.getMessage();
}
/**
* Return the HTTP status code associated with this Response.
* @return HTTP status code
*/
@Override
public int getStatus() {
return coyoteResponse.getStatus();
}
/**
* Reset this response, and specify the values for the HTTP status code
* and corresponding message.
*
* @param status The new HTTP status
* @param message The corresponding message
* @exception IllegalStateException if this response has already been
* committed
*/
@Override
public void reset(int status, String message) {
reset();
setStatus(status);
coyoteResponse.setDetailMessage(HtmlEntityEncoder.encodeXSS(message));
}
// -------------------------------------------- HttpServletResponse Methods
/**
* Add the specified Cookie to those that will be included with
* this Response.
*
* @param cookie Cookie to be added
*/
@Override
public void addCookie(final Cookie cookie) {
if (isCommitted())
return;
// Ignore any call from an included servlet
if (included)
return;
String cookieValue = getCookieString(cookie);
addHeader("Set-Cookie", cookieValue);
}
/**
* Special method for adding a session cookie as we should be overriding
* any previous
* @param cookie
*/
@Override
public void addSessionCookieInternal(final Cookie cookie) {
if (isCommitted())
return;
String name = cookie.getName();
final String headername = "Set-Cookie";
final String startsWith = name + "=";
String cookieString = getCookieString(cookie);
String cookieSameSiteValue = ((org.apache.catalina.connector.Connector) connector).getProperty("sameSiteValue");
if (cookieSameSiteValue != null) {
cookieString += ";SameSite=" + cookieSameSiteValue + ("None".equals(cookieSameSiteValue) ? ";Secure" : "");
}
boolean set = false;
MimeHeaders headers = coyoteResponse.getResponse().getHeaders();
int n = headers.size();
for (int i = 0; i < n; i++) {
if (headers.getName(i).toString().equals(headername)) {
if (headers.getValue(i).toString().startsWith(startsWith)) {
headers.getValue(i).setString(cookieString);
set = true;
}
}
}
if (!set) {
addHeader(headername, cookieString);
}
}
/**
* Add the specified date header to the specified value.
*
* @param name Name of the header to set
* @param value Date value to be set
*/
@Override
public void addDateHeader(String name, long value) {
if (name == null || name.length() == 0) {
return;
}
if (isCommitted())
return;
// Ignore any call from an included servlet
if (included) {
return;
}
if (format == null) {
format = new SimpleDateFormat(HTTP_RESPONSE_DATE_HEADER,
Locale.US);
format.setTimeZone(TimeZone.getTimeZone("GMT"));
}
addHeader(name, FastHttpDateFormat.formatDate(value, format));
}
/**
* Add the specified header to the specified value.
*
* @param name Name of the header to set
* @param value Value to be set
*/
@Override
public void addHeader(String name, String value) {
if (name == null || name.length() == 0 || value == null) {
return;
}
if (isCommitted())
return;
// Ignore any call from an included servlet
if (included)
return;
coyoteResponse.addHeader(name, value);
}
/**
* Add the specified integer header to the specified value.
*
* @param name Name of the header to set
* @param value Integer value to be set
*/
@Override
public void addIntHeader(String name, int value) {
if (name == null || name.length() == 0) {
return;
}
if (isCommitted())
return;
// Ignore any call from an included servlet
if (included)
return;
addHeader(name, "" + value);
}
/**
* Has the specified header been set already in this response?
*
* @param name Name of the header to check
* @return If header is set
*/
@Override
public boolean containsHeader(String name) {
return coyoteResponse.containsHeader(name);
}
/**
* Encode the session identifier associated with this response
* into the specified redirect URL, if necessary.
*
* @param url URL to be encoded
* @return encoded URL
*/
@Override
public String encodeRedirectURL(String url) {
if (isEncodeable(toAbsolute(url))) {
String sessionVersion = null;
Map sessionVersions = request.getSessionVersionsRequestAttribute();
if (sessionVersions != null) {
sessionVersion = createSessionVersionString(sessionVersions);
}
return toEncoded(url, request.getSessionInternal().getIdInternal(), sessionVersion);
}
return url;
}
@Override
public Supplier
© 2015 - 2025 Weber Informatics LLC | Privacy Policy