Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Request.php #427

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,37 @@
return $result;
}

/**
* Set the new value for given key in the metadata from the request header.
* This function will be useful to change metadata on the fly say in the middleware.
*
* @param string $requestedKey
* @param string $newValue
*
* @return string
*/
public function setMeta(string $requestedKey, string $newValue): string

Check warning on line 198 in src/Request.php

View check run for this annotation

Codecov / codecov/patch

src/Request.php#L198

Added line #L198 was not covered by tests
{
$uploadMetaData = $this->request->headers->get('Upload-Metadata');

Check warning on line 200 in src/Request.php

View check run for this annotation

Codecov / codecov/patch

src/Request.php#L200

Added line #L200 was not covered by tests

if (empty($uploadMetaData)) {
return '';

Check warning on line 203 in src/Request.php

View check run for this annotation

Codecov / codecov/patch

src/Request.php#L202-L203

Added lines #L202 - L203 were not covered by tests
}

$uploadMetaDataChunks = explode(',', $uploadMetaData);

Check warning on line 206 in src/Request.php

View check run for this annotation

Codecov / codecov/patch

src/Request.php#L206

Added line #L206 was not covered by tests

foreach ($uploadMetaDataChunks as $key => $chunk) {
$pieces = explode(' ', trim($chunk));
if ($pieces[0] === $requestedKey) {
$pieces[1] = base64_encode($newValue);
$uploadMetaDataChunks[$key] = implode(' ', $pieces);
break;

Check warning on line 213 in src/Request.php

View check run for this annotation

Codecov / codecov/patch

src/Request.php#L208-L213

Added lines #L208 - L213 were not covered by tests
}
}

return implode(',', $uploadMetaDataChunks);

Check warning on line 217 in src/Request.php

View check run for this annotation

Codecov / codecov/patch

src/Request.php#L217

Added line #L217 was not covered by tests
}

/**
* Extract partials from header.
*
Expand Down