Skip to content

Commit 5795b34

Browse files
authored
Throw exception for invalid headers (#23)
1 parent bbdf0b3 commit 5795b34

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

Diff for: src/Models/Request.php

+6
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ public static function create(array $data): self
5050
if (!empty($data['headers'])) {
5151
$request->headers = collect($data['headers'])
5252
->mapWithKeys(function ($header) {
53+
if (!str_contains($header, ':')) {
54+
throw new InvalidArgumentException(
55+
sprintf('The "%s" header must be a key/value pair separated by ":".', $header)
56+
);
57+
}
58+
5359
[$key, $value] = explode(':', $header, 2);
5460

5561
return [trim($key) => self::convertDataType(trim($value))];

Diff for: tests/Feature/Console/Commands/CurlCommandTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ public function test_it_throw_exception_when_for_invalid_url()
2929
Artisan::call('shift:curl -X GET "https://{domain:port}/api/{id}/"');
3030
}
3131

32+
public function test_it_throw_exception_when_for_invalid_headers()
33+
{
34+
$this->expectException(InvalidArgumentException::class);
35+
$this->expectExceptionMessage('The "foo" header must be a key/value pair separated by ":".');
36+
37+
Artisan::call("shift:curl https://example.com --header 'foo'");
38+
}
39+
3240
public function curlCommandFixtures()
3341
{
3442
return [

0 commit comments

Comments
 (0)