close method

Send the HTTP request and get the response.

Implementation

SyncHttpClientResponse close() {
  var queryString = '';
  if (uri.hasQuery) {
    var query = StringBuffer();
    query.write('?');
    uri.queryParameters.forEach((k, v) {
      query.write(Uri.encodeComponent(k));
      query.write('=');
      query.write(Uri.encodeComponent(v));
      query.write('&');
    });
    queryString = query.toString().substring(0, query.length - 1);
  }
  var buffer = StringBuffer();
  buffer.write('$method ${uri.path}$queryString HTTP/$_protocolVersion\r\n');
  headers.forEach((name, values) {
    for (var value in values) {
      buffer.write('$name: $value\r\n');
    }
  });
  buffer.write('\r\n');
  if (hasBody) {
    buffer.write(String.fromCharCodes(_body!.takeBytes()));
  }
  _socket.writeFromSync(buffer.toString().codeUnits);
  return SyncHttpClientResponse(_socket);
}