Copies all the non system headers from the original request into the new
subsequent request (Not needed for initial requests since a clone of the
request is done)

Added for Issue 1409
http://code.google.com/p/mobicents/issues/detail?id=1409
763573
private void copyNonSystemHeaders(SipServletRequestImpl origRequestImpl,
            SipServletRequestImpl newSubsequentServletRequest) {
        final Message origMessage = origRequestImpl.getMessage();
        final Message subsequentMessage = newSubsequentServletRequest.getMessage();
        ListIterator<String> headerNames = origMessage.getHeaderNames();
        while (headerNames.hasNext()) {
            String headerName = headerNames.next();
            if (!JainSipUtils.SYSTEM_HEADERS.contains(headerName) && !headerName.equalsIgnoreCase(ContactHeader.NAME)
                    && !headerName.equalsIgnoreCase(FromHeader.NAME) && !headerName.equalsIgnoreCase(ToHeader.NAME)) {
                // Issue 184 : http://code.google.com/p/sipservlets/issues/detail?id=184
                // Not all headers are copied for subsequent requests using B2buaHelper.createRequest(session, request, map)
                // Fix by Alexander Saveliev, iterate through all headers and copy them
                ListIterator<Header> origHeaderIt = origMessage.getHeaders(headerName);
                ListIterator<Header> subsHeaderIt = subsequentMessage.getHeaders(headerName);
                while (origHeaderIt.hasNext()) {
                    HeaderExt origHeader = (HeaderExt) origHeaderIt.next();
                    // Issue http://code.google.com/p/mobicents/issues/detail?id=2094
                    // B2b re-invite for authentication will duplicate Remote-Party-ID header
                    // checking if the subsequent request and original request share the same header name and value
                    // before copying to avoid duplicating the headers
                    boolean headerNameValueAlreadyPresent = false;
                    while (subsHeaderIt.hasNext() && !headerNameValueAlreadyPresent) {
                        HeaderExt subsHeader = (HeaderExt) subsHeaderIt.next();
                        if (origHeader.getValue().equals(subsHeader.getValue())) {
                            headerNameValueAlreadyPresent = true;
                        }
                    }
                    if (!headerNameValueAlreadyPresent) {
                        if (origHeader != null) {
                            subsequentMessage.addHeader(((Header) origHeader.clone()));
                            if (logger.isDebugEnabled()) {
                                logger.debug("original header " + origHeader + " copied in the new subsequent request");
                            }
                        } else {
                            // Issue 2500 http://code.google.com/p/mobicents/issues/detail?id=2500
                            // B2buaHelper.createRequest() throws a NullPointerException if the request contains an empty header
                            if (logger.isDebugEnabled()) {
                                logger.debug("trying to copy original header name " + headerName + " into the new subsequent request with an empty value");
                            }
                            try {
                                subsequentMessage.addHeader(sipFactoryImpl.getHeaderFactory().createHeader(headerName, ""));
                            } catch (ParseException e) {
                                if (logger.isDebugEnabled()) {
                                    logger.debug("couldn't copy original header name " + headerName + " into the new subsequent request with an empty value");
                                }
                            }
                        }
                    }
                }
            }
        }
    }
531821
def _copy(self):
    """"""
    copied_uri = Uri(self.uri.scheme, self.uri.host, self.uri.port,
                     self.uri.path, self.uri.query.copy())
    new_request = HttpRequest(uri=copied_uri, method=self.method,
                              headers=self.headers.copy())
    new_request._body_parts = self._body_parts[:]
    return new_request
1274624
@Nonnull
  @ReturnsMutableCopy
  public static HttpHeaderMap getRequestHeaderMap (@Nonnull final HttpServletRequest aHttpRequest)
  {
    ValueEnforcer.notNull (aHttpRequest, "HttpRequest");

    final HttpHeaderMap ret = new HttpHeaderMap ();
    final Enumeration <String> aHeaders = aHttpRequest.getHeaderNames ();
    while (aHeaders.hasMoreElements ())
    {
      final String sName = aHeaders.nextElement ();
      final Enumeration <String> eHeaderValues = aHttpRequest.getHeaders (sName);
      while (eHeaderValues.hasMoreElements ())
      {
        final String sValue = eHeaderValues.nextElement ();
        ret.addHeader (sName, sValue);
      }
    }
    return ret;
  }
640378
def cleanup_headers(self):
        """"""
        headers = {'Content-Type': 'application/json'}
        headers['Authorization'] = self.__token
        self.__headers = headers
        self.__params = {}
629074
def remove_headers(request, headers_to_remove):
    
    replacements = [(k, None) for k in headers_to_remove]
    return replace_headers(request, replacements)
1050027
def request_from_context(context):
    
    new_context = copy.deepcopy(context)
    assert new_context.method in ALLOWED_METHODS

    new_context.url_path = generate_url_path(
        new_context.url_path,
        prefix=new_context.prefix_url_path,
        format_suffix=new_context.url_path_format,
        **new_context.url_path_params
    )

    if new_context.body_params or new_context.files:
        body, content_type = new_context.renderer.encode_params(new_context.body_params, files=new_context.files)
        if new_context.update_content_type and HttpSdk.CONTENT_TYPE_HEADER_NAME not in new_context.headers:
            new_context.headers[HttpSdk.CONTENT_TYPE_HEADER_NAME] = content_type
    else:
        body = None

    authentication_instances = new_context.authentication_instances
    for auth_obj in authentication_instances:
        new_context = auth_obj.apply_authentication(new_context)

    if HttpSdk.COOKIE_HEADER_NAME not in new_context.headers and not new_context.cookie.is_empty():
        new_context.headers[HttpSdk.COOKIE_HEADER_NAME] = new_context.cookie.as_cookie_header_value()

    url = "%s%s" % (new_context.host, new_context.url_path)
    if new_context.query_params:
        url += "?%s" % (urlencode(new_context.query_params))

    log_print_request(new_context.method, url, new_context.query_params, new_context.headers, body)
    # ensure method and url are native str
    r = HttpSdk.get_pool_manager(new_context.proxy).request(
        convert_unicode_to_native_str(new_context.method),
        convert_unicode_to_native_str(url),
        body=body,
        headers=HttpSdk.convert_headers_to_native_str(new_context.headers),
        redirect=new_context.redirect,
        timeout=new_context.timeout
    )
    log_print_response(r.status, r.data, r.headers)
    r = new_context.response_class(r)
    return r
1163207
private void copyHeadersToClient(HttpURLConnection pRemoteConnection, HttpServletResponse pResponse) {
        // NOTE: There is no getHeaderFieldCount method or similar...
        // Also, the getHeaderFields() method was introduced in J2SE 1.4, and
        // we want to be 1.2 compatible.
        // So, just try to loop until there are no more headers.
        int i = 0;
        while (true) {
            String key = pRemoteConnection.getHeaderFieldKey(i);
            // NOTE: getHeaderField(String) returns only the last value
            String value = pRemoteConnection.getHeaderField(i);

            // If the key is not null, life is simple, and Sun is shining
            // However, the default implementations includes the HTTP response
            // code ("HTTP/1.1 200 Ok" or similar) as a header field with
            // key "null" (why..?)...
            // In addition, we want to skip the original "Server" header
            if (key != null && !HTTP_RESPONSE_HEADER_SERVER.equalsIgnoreCase(key)) {
                //System.out.println("client <<<-- remote: " + key + ": " + value);
                pResponse.setHeader(key, value);
            }
            else if (value == null) {
                // If BOTH key and value is null, there are no more header fields
                break;
            }

            i++;
        }

        /* 1.4+ version below....
        Map headers = pRemoteConnection.getHeaderFields();
        for (Iterator iterator = headers.entrySet().iterator(); iterator.hasNext();) {
            Map.Entry header = (Map.Entry) iterator.next();

            List values = (List) header.getValue();

            for (Iterator valueIter = values.iterator(); valueIter.hasNext();) {
                String value = (String) valueIter.next();
                String key = (String) header.getKey();

                // Skip the server header
                if (HTTP_RESPONSE_HEADER_SERVER.equalsIgnoreCase(key)) {
                    key = null;
                }

                // The default implementations includes the HTTP response code
                // ("HTTP/1.1 200 Ok" or similar) as a header field with
                // key "null" (why..?)...
                if (key != null) {
                    //System.out.println("client <<<-- remote: " + key + ": " + value);
                    pResponse.setHeader(key, value);
                }
            }
        }
        */
    }
328009
function Request_addHeader(key, value) {
        var item;
        if (Type.isString(key)) {
            key = key.toLowerCase();
            if (!Type.isString(value) && !!value && Type.isFunction(value.toString)) {
                value = value.toString();
            }
            if (Type.isString(value)) {
                if (this.hasHeader(key) && !Type.isArray(this.headers[key])) {
                    item = this.getHeader(key);
                    this.headers[key] = [];
                    this.headers[key].push(item);
                    this.headers[key].push(value);
                } else if (this.hasHeader(key) && Type.isArray(this.headers[key])) {
                    this.headers[key].push(value);
                } else {
                    this.headers[key] = value;
                }
            }
        } else {
            throw new error.HttpError(500, {
                key: key,
                value: value
            }, "Request.addHeader: Header key must be string type");
        }
    }
287110
def get_from_headers(request, key):
    
    value = request.headers.get(key)
    return to_native(value)
983072
def add_headers(self, app):
        
        @app.after_request
        def after_request(response):  # noqa
            for header, value in self.config.get('headers'):
                response.headers[header] = value
            return response
949250
function(headers, params) {
        var newHeaders = {};
        for (var header in headers)
            newHeaders[header] = headers[header];
        for (var param in params) {
            var re = new RegExp(":"+ param);
            for (var header in newHeaders) {
                if (newHeaders[header].search(re) != -1) {
                    newHeaders[header] = newHeaders[header].replace(re, params[param]);
                }
            }
        }
        return newHeaders;
    }
439494
def read_request_headers(request)
      headers = {}
      request.env.keys.each do |key|
        if EXCLUDE_REQUEST_HEADER_PATTERNS.all? { |p| !key.starts_with? p }
          headers.merge!(cleanup_header(key) => request.env[key])
        end
      end
      headers
    end
1336205
function serialiseRequest (request, toObject) {
  if (!(request instanceof Request)) {
    throw new Error('Expecting request to be instance of Request')
  }

  var headers = []
  var headerNames = request.headers.keys()
  for (var i = 0; i < headerNames.length; i++) {
    var headerName = headerNames[i]
    headers[headerName] = request.headers.get(headerName)
  }

  var serialised = {
    method: request.method,
    url: request.url,
    headers: headers,
    context: request.context,
    referrer: request.referrer,
    mode: request.mode,
    credentials: request.credentials,
    redirect: request.redirect,
    integrity: request.integrity,
    cache: request.cache,
    bodyUsed: request.bodyUsed
  }

  return request
    .blob()
    .then(blobUtil.blobToBase64String)
    .then(function (base64) {
      serialised.__body = base64
      return toObject
        ? serialised
        : JSON.stringify(serialised)
    })
}
106004
function header (request) {

    var headers = assign({}, Http.headers.common,
        !request.crossOrigin ? Http.headers.custom : {},
        Http.headers[toLower(request.method)]
    );

    each(headers, function (value, name) {
        if (!request.headers.has(name)) {
            request.headers.set(name, value);
        }
    });

}
614728
private void addHeadersToRequest(HttpRequestBase httpRequest, Request<?> request) {

        httpRequest.addHeader(HttpHeaders.HOST, getHostHeaderValue(request.getEndpoint()));

        // Copy over any other headers already in our request
        for (Entry<String, String> entry : request.getHeaders().entrySet()) {
            /*
             * HttpClient4 fills in the Content-Length header and complains if
             * it's already present, so we skip it here. We also skip the Host
             * header to avoid sending it twice, which will interfere with some
             * signing schemes.
             */
            if (!(ignoreHeaders.contains(entry.getKey()))) {
                httpRequest.addHeader(entry.getKey(), entry.getValue());
            }
        }

        /* Set content type and encoding */
        if (httpRequest.getHeaders(HttpHeaders.CONTENT_TYPE) == null || httpRequest
                .getHeaders
                        (HttpHeaders.CONTENT_TYPE).length == 0) {
            httpRequest.addHeader(HttpHeaders.CONTENT_TYPE,
                    "application/x-www-form-urlencoded; " +
                            "charset=" + DEFAULT_ENCODING.toLowerCase());
        }
    }
220448
def request_headers(headers = {}, auth: true, gzip: true)
      headers = default_headers.merge(headers)
      headers.merge!(bearer_authorization_header) if auth
      headers[ACCEPT_ENCODING] = GZIP if gzip
      headers.reject{|_,v| v.nil? || (v.respond_to?(:empty?) && v.empty?)}
    end
778838
function normalizeHeaders(headers)
{
  var ret = headers;

  if (Util.isObject(headers))
  {
    ret = {};

    // shallow copy the headers object and convert some headers like 'Accept'
    // and 'Content-Type' to lower case while copying; this is necessary
    // because the browser-request module, which we use to make http requests in
    // the browser, does not do case-insensitive checks when deciding whether to
    // insert default values for the 'accept' and 'content-type' headers; in
    // otherwise, if someone specifies an 'Accept': 'application/json' header,
    // browser-request will inject its own 'accept': 'application/json' header
    // and the browser XMLHttpRequest object will concatenate the two values and
    // send 'Accept': 'application/json, application/json' with the request
    var headerNameLowerCase;
    for (var headerName in headers)
    {
      if (headers.hasOwnProperty(headerName))
      {
        headerNameLowerCase = headerName.toLowerCase();
        if ((headerNameLowerCase === 'accept') ||
            (headerNameLowerCase === 'content-type'))
        {
          ret[headerNameLowerCase] = headers[headerName];
        }
        else
        {
          ret[headerName] = headers[headerName];
        }
      }
    }
  }

  return ret;
}