Set the request headers.

@param request the request object
@param headers to be used
774452
private void addHeaders(HttpRequest request, Map<String, String> headers) {
		for (Map.Entry<String, String> key : headers.entrySet()) {
			request.addHeader(key.getKey(), key.getValue());
		}
	}
1065973
protected void readHeaders(ApiRequest srequest, HttpServletRequest request) {
        Enumeration<String> headerNames = request.getHeaderNames();
        while (headerNames.hasMoreElements()) {
            String hname = headerNames.nextElement();
            Enumeration<String> headerValues = request.getHeaders(hname);

            while (headerValues.hasMoreElements()) {
                String hval = headerValues.nextElement();

                if (hname != null && hname.equalsIgnoreCase("accept") && hval != null && hval.startsWith("application/apiman.")) { //$NON-NLS-1$ //$NON-NLS-2$
                    if (hval.contains("+json")) { //$NON-NLS-1$
                        hval = "application/json"; //$NON-NLS-1$
                    } else if (hval.contains("+xml")) { //$NON-NLS-1$
                        hval = "text/xml"; //$NON-NLS-1$
                    }
                }
                if (hname != null && hname.equalsIgnoreCase("X-API-Version")) { //$NON-NLS-1$
                    continue;
                }
                srequest.getHeaders().add(hname, hval);
            }
        }
    }
250557
public void setAsDefault(SetAsDefaultRequest request) {
    call(
      new PostRequest(path("set_as_default"))
        .setParam("id", request.getId())
        .setParam("organization", request.getOrganization())
        .setMediaType(MediaTypes.JSON)
    ).content();
  }
624373
public HttpFileServiceBuilder setHeaders(Headers<AsciiString, String, ?> headers) {
        requireNonNull(headers, "headers");
        if (!headers.isEmpty()) {
            getOrCreateHeaders().setAll(headers);
        }
        return this;
    }
96921
private void setHeaders(XMLHttpRequest xmlHttpRequest) throws RequestException {

        if ((headers != null) && (headers.size() > 0)) {
            for (Map.Entry<String, String> header : headers.entrySet()) {
                try {
                    xmlHttpRequest.setRequestHeader(header.getKey(), header.getValue());
                } catch (JavaScriptException e) {
                    throw new RequestException(e.getMessage());
                }
            }
        } else {
            xmlHttpRequest.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
        }
    }
729342
@BuilderMethod
    public void setHttpHeaders(@NonNull Map<String, String> headers) {
        this.httpHeaders.clear();
        this.httpHeaders.putAll(headers);
    }
831324
public OkRequest<T> headers(final Map<String, String> headers) {
        if (!headers.isEmpty())
            for (Map.Entry<String, String> header : headers.entrySet())
                header(header);
        return this;
    }
1300464
def set_headers!(request)
      headers = @event['headers'] # from api gateway
      if headers # remote API Gateway
        # Forward headers from API Gateway over to the sub http request.
        # It's important to forward the headers. Here are some examples:
        #
        #   "Turbolinks-Referrer"=>"http://localhost:8888/posts/122",
        #   "Referer"=>"http://localhost:8888/posts/122",
        #   "Accept-Encoding"=>"gzip, deflate",
        #   "Accept-Language"=>"en-US,en;q=0.9,pt;q=0.8",
        #   "Cookie"=>"_demo_session=...",
        #   "If-None-Match"=>"W/\"9fa479205fc6d24ca826d46f1f6cf461\"",
        headers.each do |k,v|
          request[k] = v
        end

        # Note by the time headers get to rack later in the they get changed to:
        #
        #   request['X-Forwarded-Host'] vs env['HTTP_X_FORWARDED_HOST']
        #
        request['X-Forwarded-For'] = headers['X-Forwarded-For'] # "1.1.1.1, 2.2.2.2" # can be comma separated list
        request['X-Forwarded-Host'] = headers['Host'] # uhghn8z6t1.execute-api.us-east-1.amazonaws.com
        request['X-Forwarded-Port'] = headers['X-Forwarded-Port'] # 443
        request['X-Forwarded-Proto'] = headers['X-Forwarded-Proto'] # https # scheme
      end

      request
    end
916819
@Override
	public void setHeader(final String name, final String value) {
		LOG.debug("Setting header, " + name + '=' + value);
		headers.put(name, value);
	}
731433
public void setRequest(HttpServletRequest request) {
		WaybackRequest wbRequest = new WaybackRequest();
		wbRequest.extractHttpRequestInfo(request);
		this.wbRequest = wbRequest;
	}
219052
public HttpFileServiceBuilder addHeaders(Headers<AsciiString, String, ?> headers) {
        requireNonNull(headers, "headers");
        getOrCreateHeaders().add(headers);
        return this;
    }
253088
public void addHeader(String name, String value) {
        httpRequest.headers().add(name, value);
    }
1285478
private static void request(final Request request) {
        if (null == request) {
            WonderPush.logError("Request with null request.");
            return;
        }

        WonderPush.safeDefer(new Runnable() {
            @Override
            public void run() {
                // Decorate parameters
                WonderPushRequestParamsDecorator.decorate(request.getResource(), request.getParams());

                // Generate signature
                BasicHeader authorizationHeader = request.getAuthorizationHeader();

                // Headers
                BasicHeader[] headers = null;
                if (null != authorizationHeader) {
                    headers = new BasicHeader[1];
                    headers[0] = authorizationHeader;
                }

                String url = WonderPushUriHelper.getAbsoluteUrl(request.getResource());
                WonderPush.logDebug("requesting url: " + request.getMethod() + " " + url + "?" + request.getParams().getURLEncodedString());
                // TODO: support other contentTypes such as "application/json"
                String contentType = "application/x-www-form-urlencoded";

                // Handler
                final ResponseHandler handler = request.getHandler();
                HttpEntity entity = null;
                if (request.getParams() != null) {
                    try {
                        entity = request.getParams() != null ? request.getParams().getEntity(null) : null;
                    } catch (IOException ex) {
                        WonderPush.logError("Failed to create HttpEntity from params " + request.getParams(), ex);
                        if (handler != null) {
                            handler.onFailure(ex, new Response(""));
                        }
                        return;
                    }
                }
                final long sendDate = SystemClock.elapsedRealtime();
                JsonHttpResponseHandler jsonHandler = new JsonHttpResponseHandler() {
                    @Override
                    public void onProgress(long bytesWritten, long totalSize) {
                        // mute this
                    }

                    @Override
                    public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                        syncTime(response);
                        WonderPush.setNetworkAvailable(true);
                        if (handler != null) {
                            handler.onSuccess(statusCode, new Response(response));
                        }
                    }

                    @Override
                    public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
                        WonderPush.logError("Unexpected JSONArray answer: " + statusCode + " headers: " + Arrays.toString(headers) + " response: (" + response.length() + ") " + response.toString());
                    }

                    @Override
                    public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
                        WonderPush.logError("Error answer: " + statusCode + " headers: " + Arrays.toString(headers) + " response: " + errorResponse);
                        syncTime(errorResponse);
                        WonderPush.logDebug("Request Error: " + errorResponse);
                        WonderPush.setNetworkAvailable(errorResponse != null);
                        if (handler != null) {
                            handler.onFailure(throwable, new Response(errorResponse));
                        }
                    }

                    @Override
                    public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONArray errorResponse) {
                        WonderPush.logError("Unexpected JSONArray error answer: " + statusCode + " headers: " + Arrays.toString(headers) + " response: (" + errorResponse.length() + ") " + errorResponse.toString());
                        this.onFailure(statusCode, headers, errorResponse.toString(), throwable);
                    }

                    @Override
                    public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                        WonderPush.logError("Unexpected string error answer: " + statusCode + " headers: " + Arrays.toString(headers) + " response: (" + responseString.length() + ") \"" + responseString + "\"");
                        WonderPush.setNetworkAvailable(false);
                        if (handler != null) {
                            handler.onFailure(throwable, new Response(responseString));
                        }
                    }

                    @Override
                    public void onSuccess(int statusCode, Header[] headers, String responseString) {
                        WonderPush.logError("Unexpected string answer: " + statusCode + " headers: " + Arrays.toString(headers) + " response: (" + responseString.length() + ") \"" + responseString + "\"");
                    }

                    private void syncTime(JSONObject data) {
                        long recvDate = SystemClock.elapsedRealtime();
                        if (data == null || !data.has("_serverTime")) {
                            return;
                        }
                        TimeSync.syncTimeWithServer(sendDate, recvDate, data.optLong("_serverTime"), data.optLong("_serverTook"));
                    }
                };
                // NO UNNECESSARY WORK HERE, because of timed request
                switch (request.getMethod()) {
                    case GET:
                        sClient.get(null, url, headers, request.getParams(), jsonHandler);
                        break;
                    case PUT:
                        sClient.put(null, url, headers, entity, contentType, jsonHandler);
                        break;
                    case POST:
                        sClient.post(null, url, headers, entity, contentType, jsonHandler);
                        break;
                    case PATCH:
                        sClient.patch(null, url, headers, entity, contentType, jsonHandler);
                        break;
                    case DELETE:
                        sClient.delete(null, url, headers, request.getParams(), jsonHandler);
                        break;
                    default:
                        jsonHandler.sendFailureMessage(0, null, null, new UnsupportedOperationException("Unhandled method " + request.getMethod()));
                }
            }
        }, 0);
    }
876969
private static void addHeaderIfNotNull(Request<?> request, String header, String value) {
        if (value != null) {
            request.addHeader(header, value);
        }
    }
117749
private void setUpgradeRequestHeaders(ChannelHandlerContext ctx, HttpRequest request) {
        // Set the UPGRADE header on the request.
        request.headers().set(HttpHeaderNames.UPGRADE, upgradeCodec.protocol());

        // Add all protocol-specific headers to the request.
        Set<CharSequence> connectionParts = new LinkedHashSet<CharSequence>(2);
        connectionParts.addAll(upgradeCodec.setUpgradeHeaders(ctx, request));

        // Set the CONNECTION header from the set of all protocol-specific headers that were added.
        StringBuilder builder = new StringBuilder();
        for (CharSequence part : connectionParts) {
            builder.append(part);
            builder.append(',');
        }
        builder.append(HttpHeaderValues.UPGRADE);
        request.headers().add(HttpHeaderNames.CONNECTION, builder.toString());
    }
738153
public void doHead(String url, HttpResponse response, Map<String, Object> headers) {
        response.setRequest(url);
        httpClient.head(url, response, headers);
    }
564395
public void setHeader(java.util.Collection<String> header) {
        if (header == null) {
            this.header = null;
            return;
        }

        this.header = new java.util.ArrayList<String>(header);
    }