Skip to content

Commit

Permalink
http client defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
asika32764 committed Oct 5, 2024
1 parent bfecdc1 commit 456e326
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions packages/http/src/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,43 @@ public function getBaseUri(): string
return (string) $this->getOption('base_uri');
}

public function withOptions(array $options = []): static
public function withOptions(array $options = [], bool $merge = false): static
{
$new = clone $this;
$new->options = $options;

if ($merge) {
$new->options = Arr::mergeRecursive(
$this->options,
$options
);
} else {
$new->options = $options;
}

return $new;
}

public function withDefaultHeader(string $name, string|array $value): static
{
$new = clone $this;

$new->options['headers'][$name] = $value;

return $new;
}

public function withDefaultHeaders(array $headers, bool $merge = false): static
{
$new = clone $this;

if ($merge) {
$new->options['headers'] = array_merge(
$new->options['headers'] ?? [],
$headers
);
} else {
$new->options['headers'] = $headers;
}

return $new;
}
Expand Down

0 comments on commit 456e326

Please sign in to comment.