def handle_header_and_return(header, id)
      if header
        header = header_to_json(header)
        bytes = header[:bytes]

        # Read more bytes (the actual response body)
        res = @out.read(bytes.to_i)

        if header[:method] == "highlight"
          # Make sure we have a result back; else consider this an error.
          if res.nil?
            @log.warn "No highlight result back from mentos."
            stop "No highlight result back from mentos."
            raise MentosError, "No highlight result back from mentos."
          end

          # Remove the newline from Python
          res = res[0..-2]
          @log.info "Highlight in process."

          # Get the id's
          start_id = res[0..7]
          end_id = res[-8..-1]

          # Sanity check.
          if not (start_id == id and end_id == id)
            @log.error "ID's did not match. Aborting."
            stop "ID's did not match. Aborting."
            raise MentosError, "ID's did not match. Aborting."
          else
            # We're good. Remove the padding
            res = res[10..-11]
            @log.info "Highlighting complete."
            res
          end
        end
        res
      else
        @log.error "No header data back."
        stop "No header data back."
        raise MentosError, "No header received back."
      end
    end
def handle_header_and_return(header, id)
      if header
        header = header_to_json(header)
        bytes = header[:bytes]

        # Read more bytes (the actual response body)
        res = @out.read(bytes.to_i)

        if header[:method] == "highlight"
          # Make sure we have a result back; else consider this an error.
          if res.nil?
            @log.warn "No highlight result back from mentos."
            stop "No highlight result back from mentos."
            raise MentosError, "No highlight result back from mentos."
          end

          # Remove the newline from Python
          res = res[0..-2]
          @log.info "Highlight in process."

          # Get the id's
          start_id = res[0..7]
          end_id = res[-8..-1]

          # Sanity check.
          if not (start_id == id and end_id == id)
            @log.error "ID's did not match. Aborting."
            stop "ID's did not match. Aborting."
            raise MentosError, "ID's did not match. Aborting."
          else
            # We're good. Remove the padding
            res = res[10..-11]
            @log.info "Highlighting complete."
            res
          end
        end
        res
      else
        @log.error "No header data back."
        stop "No header data back."
        raise MentosError, "No header received back."
      end
    end
Based on the header we receive, determine if we need
 to read more bytes, and read those bytes if necessary.

 Then, do a sanity check with the ids.

 Returns a result — either highlighted text or metadata.