if (first)
StringBuilder sb = new StringBuilder(); boolean first = true; for (Method method : response.getEntity().getResource().getAllowedMethods())
	protected void addResponseHeaders(HttpServerCall httpCall, Response response)	{		try		{			// Add all the necessary response headers			ParameterList responseHeaders = httpCall.getResponseHeaders();			if (response.getStatus().equals(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED)					|| response.getRequest().getMethod().equals(Method.PUT))			{				// Format the "Allow" header				StringBuilder sb = new StringBuilder();				boolean first = true;				for (Method method : response.getEntity().getResource().getAllowedMethods())				{					if (first)					{						first = false;					}					else					{						sb.append(", ");					}					sb.append(method.getName());				}				responseHeaders.add(HttpConstants.HEADER_ALLOW, sb.toString());			}			// Add the cookie settings			List<CookieSetting> cookies = response.getCookieSettings();			for (int i = 0; i < cookies.size(); i++)			{				responseHeaders.add(HttpConstants.HEADER_SET_COOKIE, CookieUtils						.format(cookies.get(i)));			}			// Set the redirection URI			if (response.getRedirectRef() != null)			{				responseHeaders.add(HttpConstants.HEADER_LOCATION, response.getRedirectRef()						.toString());			}			// Set the security data			if (response.getChallengeRequest() != null)			{				responseHeaders.add(HttpConstants.HEADER_WWW_AUTHENTICATE, SecurityUtils						.format(response.getChallengeRequest()));			}			// Set the server name again			httpCall.getResponseHeaders().add(HttpConstants.HEADER_SERVER,					response.getServerInfo().getAgent());			// Set the status code in the response			if (response.getStatus() != null)			{				httpCall.setStatusCode(response.getStatus().getCode());				httpCall.setReasonPhrase(response.getStatus().getDescription());			}			// If an entity was set during the call, copy it to the output stream;			if (response.getEntity() != null)			{				Representation entity = response.getEntity();				if (entity.getExpirationDate() != null)				{					responseHeaders.add(HttpConstants.HEADER_EXPIRES, httpCall.formatDate(							entity.getExpirationDate(), false));				}				if ((entity.getEncoding() != null)						&& (!entity.getEncoding().equals(Encoding.IDENTITY)))				{					responseHeaders.add(HttpConstants.HEADER_CONTENT_ENCODING, entity							.getEncoding().getName());				}				if (entity.getLanguage() != null)				{					responseHeaders.add(HttpConstants.HEADER_CONTENT_LANGUAGE, entity							.getLanguage().getName());				}				if (entity.getMediaType() != null)				{					StringBuilder contentType = new StringBuilder(entity.getMediaType()							.getName());					if (entity.getCharacterSet() != null)					{						// Specify the character set parameter						contentType.append("; charset=").append(								entity.getCharacterSet().getName());					}					responseHeaders.add(HttpConstants.HEADER_CONTENT_TYPE, contentType							.toString());				}				if (entity.getModificationDate() != null)				{					responseHeaders.add(HttpConstants.HEADER_LAST_MODIFIED, httpCall							.formatDate(entity.getModificationDate(), false));				}				if (entity.getTag() != null)				{					responseHeaders.add(HttpConstants.HEADER_ETAG, entity.getTag().getName());				}				if (response.getEntity().getSize() != Representation.UNKNOWN_SIZE)				{					responseHeaders.add(HttpConstants.HEADER_CONTENT_LENGTH, Long							.toString(response.getEntity().getSize()));				}				if (response.getEntity().getIdentifier() != null)				{					responseHeaders.add(HttpConstants.HEADER_CONTENT_LOCATION, response							.getEntity().getIdentifier().toString());				}			}			// Add user-defined extension headers			ParameterList additionalHeaders = (ParameterList) response.getAttributes().get(					HttpConstants.ATTRIBUTE_HEADERS);			addAdditionalHeaders(responseHeaders, additionalHeaders);		}		catch (Exception e)		{			getLogger().log(Level.INFO,					"Exception intercepted while adding the response headers", e);			httpCall.setStatusCode(Status.SERVER_ERROR_INTERNAL.getCode());			httpCall.setReasonPhrase(Status.SERVER_ERROR_INTERNAL.getDescription());		}	}