class_docstr: Implements the HTTP/1.x protocol.
  
  This class can be on its own for clients, or via `HTTP1ServerConnection`
  for servers.
class_docstr_tok: ["Implements","the","HTTP\/1.x","protocol",".","This","class","can","be","on","its","own","for","clients",",","or","via","`","HTTP1ServerConnection","`","for","servers","."]
docstr: Implements `.HTTPConnection.write_headers`.
docstr_tok: ["Implements","`",".HTTPConnection.write_headers","`","."]
code: def write_headers(
      self, start_line, headers, chunk=None, callback=None
  ):
      """Implements `.HTTPConnection.write_headers`."""
      lines = []
      if self.is_client:
          self._request_start_line = start_line
          lines.append(
              utf8("%s %s HTTP/1.1" % (start_line[0], start_line[1]))
          )
          # Client requests with a non-empty body must have either a
          # Content-Length or a Transfer-Encoding.
          self._chunking_output = (
              start_line.method in ("POST", "PUT", "PATCH")
              and "Content-Length" not in headers
              and "Transfer-Encoding" not in headers
          )
      else:
          self._response_start_line = start_line
          lines.append(
              utf8("HTTP/1.1 %d %s" % (start_line[1], start_line[2]))
          )
          self._chunking_output = (
              # TODO: should this use
              # self._request_start_line.version or
              # start_line.version?
              self._request_start_line.version == "HTTP/1.1"
              and
              # 1xx, 204 and 304 responses have no body (not even a zero-length
              # body), and so should not have either Content-Length or
              # Transfer-Encoding headers.
              start_line.code not in (204, 304)
              and (start_line.code < 100 or start_line.code >= 200)
              and
              # No need to chunk the output if a Content-Length is specified.
              "Content-Length" not in headers
              and
              # Applications are discouraged from touching Transfer-Encoding,
              # but if they do, leave it alone.
              "Transfer-Encoding" not in headers
          )
          # If a 1.0 client asked for keep-alive, add the header.
          if self._request_start_line.version == "HTTP/1.0" and (
              self._request_headers.get("Connection", "").lower()
              == "keep-alive"
          ):
              headers["Connection"] = "Keep-Alive"
      if self._chunking_output:
          headers["Transfer-Encoding"] = "chunked"
      if not self.is_client and (
          self._request_start_line.method == "HEAD"
          or start_line.code == 304
      ):
          self._expected_content_remaining = 0
      elif "Content-Length" in headers:
          self._expected_content_remaining = int(
              headers["Content-Length"]
          )
      else:
          self._expected_content_remaining = None
      # TODO: headers are supposed to be of type str, but we still have some
      # cases that let bytes slip through. Remove these native_str calls when those
      # are fixed.
      header_lines = (
          native_str(n) + ": " + native_str(v)
          for n, v in headers.get_all()
      )
      if PY3:
          lines.extend(l.encode("latin1") for l in header_lines)
      else:
          lines.extend(header_lines)
      for line in lines:
          if b"\n" in line:
              raise ValueError("Newline in header: " + repr(line))
      future = None
      if self.stream.closed():
          future = self._write_future = Future()
          future.set_exception(iostream.StreamClosedError())
          future.exception()
      else:
          if callback is not None:
              self._write_callback = stack_context.wrap(callback)
          else:
              future = self._write_future = Future()
          data = b"\r\n".join(lines) + b"\r\n\r\n"
          if chunk:
              data += self._format_chunk(chunk)
          self._pending_write = self.stream.write(data)
          self._pending_write.add_done_callback(self._on_write_complete)
      return future
  
imports: from __future__ import absolute_import, division, print_function
  import re
  from tornado.concurrent import Future
  from tornado.escape import native_str, utf8
  from tornado import gen
  from tornado import httputil
  from tornado import iostream
  from tornado.log import gen_log, app_log
  from tornado import stack_context
  from tornado.util import GzipDecompressor, PY3
label_desc: Use image node_id 11 for calling the HTTP1Connection obj's underlying member method code with example usage: obj.write_headers(start_line, headers, chunk, callback) and returns: future