/*
(non-Javadoc)
@see javax.servlet.sip.SipServletRequest#addAuthHeader(javax.servlet.sip.SipServletResponse, java.lang.String, java.lang.String)
14773
public void addAuthHeader(SipServletResponse challengeResponse,
			String username, String password) {
		addAuthHeader(challengeResponse, username, password, false);
	}
1080921
private void setHeader(HttpServletResponse response, String name, String value) {
        if(response.containsHeader(value)) {
              response.setHeader(name, value);
        } else {
            response.addHeader(name, value);
        }
    }
1017487
private void addKeepAliveHeaders(HttpHeaders headers) {
        if (protocol == H1 || protocol == H1C) {
            headers.set(HttpHeaderNames.CONNECTION, "keep-alive");
        } else {
            // Do not add the 'connection' header for HTTP/2 responses.
            // See https://tools.ietf.org/html/rfc7540#section-8.1.2.2
        }
    }
61180
public void addAddressHeader(String name, Address addr, boolean first)
			throws IllegalArgumentException {

		checkCommitted();
		String hName = getFullHeaderName(name);

		if (logger.isDebugEnabled()) {
			logger.debug("Adding address header [" + hName + "] as first ["
					+ first + "] value [" + addr + "]");
		}

		//we should test for
		//This method can be used with headers which are defined to contain one
		//or more entries matching (name-addr | addr-spec) *(SEMI generic-param) as defined in RFC 3261
//		if (!isAddressTypeHeader(hName)) {
//			logger.error("Header [" + hName + "] is not address type header");
//			throw new IllegalArgumentException("Header[" + hName
//					+ "] is not of an address type");
//		}

		if (isSystemHeaderAndNotGruu(getModifiableRule(hName), (Parameterable)addr.getURI())) {
			logger.error("Error, can't add system header [" + hName + "]");
			throw new IllegalArgumentException("Header[" + hName
					+ "] is system header, cant add, modify it!!!");
		}

		if (hName.equalsIgnoreCase("From") || hName.equalsIgnoreCase("To")) {
			logger.error("Error, can't add From or To header [" + hName + "]");
			throw new IllegalArgumentException(
					"Can't add From or To header, see JSR 289 Section 4.1.2");
		}

		try {
			String nameToAdd = getCorrectHeaderName(hName);
			Header h = SipFactoryImpl.headerFactory.createHeader(nameToAdd, addr.toString());

			if (first) {
				this.message.addFirst(h);
			} else {
				this.message.addLast(h);
			}
		} catch (Exception e) {
			throw new IllegalArgumentException("Error adding header", e);
		}

	}
601613
protected ClientHttpRequestInterceptor buildAddBasicAuthHeaderRequestInterceptor(String user, String password){
		return new AddHeaderRequestInterceptor(HEADER_AUTHORIZATION, buildBasicAuthValue(user, password));
	}
954946
public void updateAuthorizationHeaders(boolean useNextNonce) {
		if(logger.isDebugEnabled()) {
			logger.debug("Updating authorization headers with nextnonce " + getSipSession().getSipSessionSecurity().getNextNonce());
		}
		int nc = -1;

		List<Header> authorizationHeaders = new ArrayList<Header>();

		// First check for WWWAuthentication headers
		ListIterator authHeaderIterator =
			message.getHeaders(AuthorizationHeader.NAME);
		while(authHeaderIterator.hasNext()) {
			AuthorizationHeader wwwAuthHeader =
				(AuthorizationHeader) authHeaderIterator.next();
			MobicentsAuthInfoEntry authInfoEntry = getSipSession().getSipSessionSecurity().getCachedAuthInfos().get(wwwAuthHeader.getRealm());

			if(authInfoEntry != null) {

				if(nc < 0) {
					nc = generateNcFromMessage(message);
				}
				String nextNonce = null;
				if(useNextNonce) {
					nextNonce = getSipSession().getSipSessionSecurity().getNextNonce();
				} else {
					nextNonce = wwwAuthHeader.getNonce();
				}

				AuthorizationHeader authorization = getSipSession().getSipApplicationSession().getSipContext().getDigestAuthenticator().getAuthorizationHeader(
						getMethod(),
						this.getRequestURI().toString(),
						"", // TODO: What is this entity-body?
						wwwAuthHeader,
						authInfoEntry.getUserName(),
						authInfoEntry.getPassword(),
						nextNonce,
						nc);

				authorizationHeaders.add(authorization);
			} else {
				authorizationHeaders.add(wwwAuthHeader);
			}
		}

		// Now check for Proxy-Authentication
		authHeaderIterator =
			message.getHeaders(ProxyAuthorizationHeader.NAME);
		while(authHeaderIterator.hasNext()) {
			ProxyAuthorizationHeader proxyAuthHeader =
				(ProxyAuthorizationHeader) authHeaderIterator.next();
//			String uri = wwwAuthHeader.getParameter("uri");
			MobicentsAuthInfoEntry authInfoEntry = getSipSession().getSipSessionSecurity().getCachedAuthInfos().get(proxyAuthHeader.getRealm());

			if(authInfoEntry != null) {

				if(nc < 0) {
					nc = generateNcFromMessage(message);
				}
				String nextNonce = null;
				if(useNextNonce) {
					nextNonce = getSipSession().getSipSessionSecurity().getNextNonce();
				} else {
					nextNonce = proxyAuthHeader.getNonce();
				}
				AuthorizationHeader authorization = getSipSession().getSipApplicationSession().getSipContext().getDigestAuthenticator().getAuthorizationHeader(
						getMethod(),
						this.getRequestURI().toString(),
						"", // TODO: What is this entity-body?
						proxyAuthHeader,
						authInfoEntry.getUserName(),
						authInfoEntry.getPassword(),
						nextNonce,
						nc);

				authorizationHeaders.add(authorization);
			} else {
				authorizationHeaders.add(proxyAuthHeader);
			}
		}

		message.removeHeader(AuthorizationHeader.NAME);
		message.removeHeader(ProxyAuthorizationHeader.NAME);

		for(Header header : authorizationHeaders) {
			message.addHeader(header);
		}
	}
528327
public void addHeader(String key, String value) {
    this.headers = addToMap(key, value, this.headers);
  }
820658
function addAuthHeaders ({ 
  auth,
  bearerToken, 
  headers, 
  overrideHeaders=false, 
}) {
  if (overrideHeaders) return
  if (bearerToken) return { 
    headers: { ...headers, Authorization: `Bearer ${ bearerToken }` } 
  }
  if (auth) {
    const username = auth.username || ''
    const password = auth.password || ''
    const encodedToken = Base64.btoa(`${ username }:${ password }`)
    return {
      headers: { ...headers, Authorization: `Basic ${ encodedToken }` }
    }
  }
}
1288352
public Map<String, String> addRequestHeader(String key, String value) {
    this.requestHeaders.put(key, value);
    return getRequestHeaders();
  }
1050214
public HttpAuthServiceBuilder addOAuth1a(Authorizer<? super OAuth1aToken> authorizer, AsciiString header) {
        return addTokenAuthorizer(new OAuth1aTokenExtractor(requireNonNull(header, "header")),
                                  requireNonNull(authorizer, "authorizer"));
    }
1273283
@NotNull
	public HttpResponse withHeader(@NotNull HttpHeader header, @NotNull String value) {
		addHeader(header, value);
		return this;
	}
299196
private short addTrackedHeader(final short index, final SipHeader header) {
        if (index != -1) {
            headers.set(index, header.ensure());
            return index;
        }
        return addHeader(header.ensure());
    }
1347047
public void addHeader(String name, String value) {
        headerEntries.add(new HeaderEntry(name, value));
    }
373142
@SuppressWarnings("unchecked")
	public T addHeader(final String name, final String value) {
		List<String> values = new ArrayList<String>();
		values.add(value);

		this.headers.put(name, values);
		return (T) this;
	}
855758
protected HttpRequest addAuthHeader(HttpRequest request) {
        if (authToken != null) {
            request.header("authorization", "Bearer " + authToken);
        }

        return request;
    }
881150
public BoxHttpRequest addHeader(String key, String value) {
        mUrlConnection.addRequestProperty(key, value);
        return this;
    }
1155456
public void setRequestHeader(String header, String value) {
        LOG.entering(CLASS_NAME, "setRequestHeader", new Object[] {header, value});
        HttpRequestUtil.validateHeader(header);
        connection.addRequestProperty(header, value);
    }