Serializes the given headers and creates a list of OkHttp {@link Header}s to be used when
creating a stream. Since this serializes the headers, this method should be called in the
application thread context.
977391
public static List<Header> createRequestHeaders(
      Metadata headers, String defaultPath, String authority, String userAgent, boolean useGet) {
    Preconditions.checkNotNull(headers, "headers");
    Preconditions.checkNotNull(defaultPath, "defaultPath");
    Preconditions.checkNotNull(authority, "authority");

    // Discard any application supplied duplicates of the reserved headers
    headers.discardAll(GrpcUtil.CONTENT_TYPE_KEY);
    headers.discardAll(GrpcUtil.TE_HEADER);
    headers.discardAll(GrpcUtil.USER_AGENT_KEY);

    // 7 is the number of explicit add calls below.
    List<Header> okhttpHeaders = new ArrayList<>(7 + InternalMetadata.headerCount(headers));

    // Set GRPC-specific headers.
    okhttpHeaders.add(SCHEME_HEADER);
    if (useGet) {
      okhttpHeaders.add(METHOD_GET_HEADER);
    } else {
      okhttpHeaders.add(METHOD_HEADER);
    }

    okhttpHeaders.add(new Header(Header.TARGET_AUTHORITY, authority));
    String path = defaultPath;
    okhttpHeaders.add(new Header(Header.TARGET_PATH, path));

    okhttpHeaders.add(new Header(GrpcUtil.USER_AGENT_KEY.name(), userAgent));

    // All non-pseudo headers must come after pseudo headers.
    okhttpHeaders.add(CONTENT_TYPE_HEADER);
    okhttpHeaders.add(TE_HEADER);

    // Now add any application-provided headers.
    byte[][] serializedHeaders = TransportFrameUtil.toHttp2Headers(headers);
    for (int i = 0; i < serializedHeaders.length; i += 2) {
      ByteString key = ByteString.of(serializedHeaders[i]);
      String keyString = key.utf8();
      if (isApplicationHeader(keyString)) {
        ByteString value = ByteString.of(serializedHeaders[i + 1]);
        okhttpHeaders.add(new Header(key, value));
      }
    }

    return okhttpHeaders;
  }
483254
@Override
    public List<String> headers(String name) {
        return request.headers().get(name);
    }
1274831
@SuppressWarnings("unchecked")
    public void setHeaders(final Map<String, Object> headers) {
        this.headers.clear();
        for (Map.Entry<String, Object> entry: headers.entrySet()) {
            if (entry.getValue() instanceof List) {
                List value = (List) entry.getValue();
                // verify they are all strings
                for (Object o: value) {
                    Assert.isTrue(o instanceof String, o + " is not a string it is a: '" +
                            o.getClass() + "'");
                }
                this.headers.put(entry.getKey(), (List<String>) entry.getValue());
            } else if (entry.getValue() instanceof String) {
                final List<String> value = Collections.singletonList((String) entry.getValue());
                this.headers.put(entry.getKey(), value);
            } else {
                throw new IllegalArgumentException("Only strings and list of strings may be headers");
            }
        }
    }
405972
public T headers(Map<String, Object> headers) {
        getMessageContentBuilder().getMessageHeaders().putAll(headers);
        return self;
    }
551075
public static Map<String, String> headers(){
        Map<String, String> headers = new HashMap<>();
        Enumeration<String> names = RequestContext.getHttpRequest().getHeaderNames();
        while (names.hasMoreElements()) {
            String name = names.nextElement();
            headers.put(name, RequestContext.getHttpRequest().getHeader(name));
        }
        return headers;
    }
1320279
public RequestTemplate headers(Map<String, Collection<String>> headers) {
    if (headers != null && !headers.isEmpty()) {
      headers.forEach(this::header);
    } else {
      this.headers.clear();
    }
    return this;
  }
156202
static List<HpackHeader> createHeaders(int numHeaders, int nameLength, int valueLength,
                                           boolean limitToAscii) {
        List<HpackHeader> hpackHeaders = new ArrayList<HpackHeader>(numHeaders);
        for (int i = 0; i < numHeaders; ++i) {
            byte[] name = randomBytes(new byte[nameLength], limitToAscii);
            byte[] value = randomBytes(new byte[valueLength], limitToAscii);
            hpackHeaders.add(new HpackHeader(name, value));
        }
        return hpackHeaders;
    }
1113023
@SuppressWarnings("unchecked")
	public T setHeaders(final Map<String, List<String>> headers) {
		this.headers = headers;
		return (T) this;
	}
198171
public static void serializeAsStream(Object o, OutputStream s) throws IOException {
        try {
            JsonStructure builtJsonObject = findFieldsToSerialize(o).mainObject;
            Map<String, Object> config = new HashMap<String, Object>();
            config.put(JsonGenerator.PRETTY_PRINTING, true);
            JsonWriterFactory writerFactory = Json.createWriterFactory(config);
            JsonWriter streamWriter = writerFactory.createWriter(s);
            streamWriter.write(builtJsonObject);
        } catch (IllegalStateException ise) {
            // the reflective attempt to build the object failed.
            throw new IOException("Unable to build JSON for Object", ise);
        } catch (JsonException e) {
            throw new IOException("Unable to build JSON for Object", e);
        }
    }
567336
public StreamMessageHeader createHeader(Object input) throws ConvertFailException
    {
        StreamMessageHeader header = new StreamMessageHeader();
        header.setType(getType());

        return header;
    }
477785
public static SOAPMessage createSoapFromStream(Map<String,String> headers, InputStream is){
        return createSoapFromStream(null,headers,is);
    }
551464
@SafeVarargs
    public final RequestBuilder headers(Map.Entry<String, ?>... headers) {
        headers(Lists.of(headers));
        return this;
    }
1328846
private void addHeadersToContext(final HttpHeaders headers) {
        for (HttpHeader header : headers.all()) {
            final String rawKey = header.key();
            final String transformedKey = rawKey.replaceAll("-", "");
            context.put("requestHeader".concat(transformedKey), header.values()
                    .toString());
        }
    }
209141
private void writeLines(final HttpServletResponse response, final ArrayList<String> lines, final String header)
      throws IOException {
    LOG.log(Level.INFO, "HttpServerReefEventHandler writeLines is called");

    final PrintWriter writer = response.getWriter();

    writer.println("<h1>" + header + "</h1>");

    for (final String line : lines) {
      writer.println(line);
      writer.write("<br/>");
    }
    writer.write("<br/>");
  }
450817
public void write(OutputStream out) throws IOException {
		for(HttpHeader header: this) {
			header.write(out);
		}
		out.write(CR);
		out.write(LF);
	}
728681
public void writeHeaders(HttpResponse response,Resource resource, long count)
        throws IOException
    {
        ResourceCache.ResourceMetaData metaData =
            (ResourceCache.ResourceMetaData)resource.getAssociate();

        response.setContentType(metaData.getMimeType());
        if (count != -1)
        {
            if (count==resource.length())
                response.setField(HttpFields.__ContentLength,metaData.getLength());
            else
                response.setContentLength((int)count);
        }

        response.setField(HttpFields.__LastModified,metaData.getLastModified());
        
        if (_acceptRanges && response.getHttpRequest().getDotVersion()>0)
            response.setField(HttpFields.__AcceptRanges,"bytes");
    }
1257222
private void setHeaderList(Map<String, List<String>> headers, String name, String value) {

        List<String> values = new ArrayList<String>();
        values.add(SET_HEADER + value);
        headers.put(name, values);
    }