Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
27pchrisl committed Apr 12, 2024
1 parent d175a87 commit 05201c4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/Helper/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Constants
public const cacheControl = 'cache-control';
public const charset = 'charset';
public const contentEncoding = 'content-encoding';
public const contentId = 'content-id';
public const contentLanguage = 'content-language';
public const contentType = 'content-type';
public const date = 'date';
Expand Down
24 changes: 22 additions & 2 deletions src/PathSegment/Batch/Multipart.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Flat3\Lodata\Controller\Transaction;
use Flat3\Lodata\Exception\Protocol\BadRequestException;
use Flat3\Lodata\Exception\Protocol\ProtocolException;
use Flat3\Lodata\Helper\Constants;
use Flat3\Lodata\Interfaces\ContextInterface;
use Flat3\Lodata\Interfaces\ResourceInterface;
use Flat3\Lodata\Interfaces\StreamInterface;
Expand Down Expand Up @@ -79,7 +80,6 @@ public function emitStream(Transaction $transaction): void

array_shift($this->boundaries);
} else {
$transaction->sendOutput("content-type: application/http\r\n\r\n");
$requestTransaction = new Transaction();
$requestTransaction->initialize(new Request($document->toRequest()));

Expand All @@ -92,6 +92,26 @@ public function emitStream(Transaction $transaction): void
$response = $e->toResponse();
}

$responseHeaders = [
Constants::contentType => ['application/http'],
];

$requestHeaders = $document->getHeaders();

foreach ([Constants::contentId] as $key) {
if (array_key_exists($key, $requestHeaders)) {
$responseHeaders[$key] = $requestHeaders[$key];
}
}

foreach ($responseHeaders as $key => $values) {
foreach ($values as $value) {
$transaction->sendOutput(strtolower((string) $key).': '.$value."\r\n");
}
}

$transaction->sendOutput("\r\n");

$transaction->sendOutput(sprintf(
"HTTP/%s %s %s\r\n",
$response->getProtocolVersion(),
Expand All @@ -101,7 +121,7 @@ public function emitStream(Transaction $transaction): void

foreach ($this->getResponseHeaders($response) as $key => $values) {
foreach ($values as $value) {
$transaction->sendOutput($key.': '.$value."\r\n");
$transaction->sendOutput(strtolower($key).': '.$value."\r\n");
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/Transaction/MultipartDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ public function setHeaders(array $headers): self
return $this;
}

/**
* Get the headers of this document
* @return array
*/
public function getHeaders(): array
{
return $this->headers;
}

/**
* Set the body of this document
* @param string $body
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

--00000000-0000-0000-0000-000000000002
content-type: application/http
content-id: 1

HTTP/1.1 406 Not Acceptable
content-type: application/json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ content-type: multipart/mixed;boundary=00000000-0000-0000-0000-000000000004

--00000000-0000-0000-0000-000000000004
content-type: application/http
content-id: 1

HTTP/1.0 201 Created
content-type: application/json;metadata=minimal
Expand All @@ -22,6 +23,7 @@ etag: W/"9dcfebb4cce3bc22f0333343727cdc6ef96cc0d0026b89ca181a1c40cb250907"
{"@context":"http://localhost/odata/$metadata#airports/$entity","id":5,"name":"One","code":"one","construction_date":null,"open_time":null,"sam_datetime":null,"review_score":null,"is_big":null,"country_id":null}
--00000000-0000-0000-0000-000000000004
content-type: application/http
content-id: 2

HTTP/1.1 412 Precondition Failed
content-type: application/json
Expand Down

0 comments on commit 05201c4

Please sign in to comment.