cookie method

TestRequest cookie(
  1. String name,
  2. String value
)

Add a cookie to the request.

Automatically formats cookies into the Cookie header. Multiple cookies are properly separated with semicolons.

Example:

testApp.get('/api/profile')
  .cookie('session_id', 'abc123')
  .cookie('preferences', 'dark_mode=true');

name Cookie name. value Cookie value. Returns this request builder for method chaining.

Implementation

TestRequest cookie(String name, String value) {
  final existingCookies = _headers['cookie'] ?? '';
  final newCookie = '$name=$value';

  if (existingCookies.isEmpty) {
    _headers['cookie'] = newCookie;
  } else {
    _headers['cookie'] = '$existingCookies; $newCookie';
  }

  return this;
}