Completed
Push — master ( ad6cef...3263d6 )
by Ankit
02:24
created

Server::exit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace TusPhp\Tus;
4
5
use TusPhp\File;
6
use Carbon\Carbon;
7
use TusPhp\Request;
8
use TusPhp\Response;
9
use Ramsey\Uuid\Uuid;
10
use TusPhp\Cache\Cacheable;
11
use TusPhp\Exception\FileException;
12
use TusPhp\Exception\ConnectionException;
13
use TusPhp\Exception\OutOfRangeException;
14
use Illuminate\Http\Request as HttpRequest;
15
use Illuminate\Http\Response as HttpResponse;
16
use Symfony\Component\HttpFoundation\BinaryFileResponse;
17
18
class Server extends AbstractTus
19
{
20
    /** @const string Tus Creation Extension */
21
    const TUS_EXTENSION_CREATION = 'creation';
22
23
    /** @const string Tus Termination Extension */
24
    const TUS_EXTENSION_TERMINATION = 'termination';
25
26
    /** @const string Tus Checksum Extension */
27
    const TUS_EXTENSION_CHECKSUM = 'checksum';
28
29
    /** @const string Tus Expiration Extension */
30
    const TUS_EXTENSION_EXPIRATION = 'expiration';
31
32
    /** @const string Tus Concatenation Extension */
33
    const TUS_EXTENSION_CONCATENATION = 'concatenation';
34
35
    /** @const array All supported tus extensions */
36
    const TUS_EXTENSIONS = [
37
        self::TUS_EXTENSION_CREATION,
38
        self::TUS_EXTENSION_TERMINATION,
39
        self::TUS_EXTENSION_CHECKSUM,
40
        self::TUS_EXTENSION_EXPIRATION,
41
        self::TUS_EXTENSION_CONCATENATION,
42
    ];
43
44
    /** @const int 460 Checksum Mismatch */
45
    const HTTP_CHECKSUM_MISMATCH = 460;
46
47
    /** @const string Default checksum algorithm */
48
    const DEFAULT_CHECKSUM_ALGORITHM = 'sha256';
49
50
    /** @const int 24 hours access control max age header */
51
    const HEADER_ACCESS_CONTROL_MAX_AGE = 86400;
52
53
    /** @var Request */
54
    protected $request;
55
56
    /** @var Response */
57
    protected $response;
58
59
    /** @var string */
60
    protected $uploadDir;
61
62
    /** @var string */
63
    protected $uploadKey;
64
65
    /** @var array */
66
    protected $globalHeaders;
67
68
    /**
69
     * @var int Max upload size in bytes
70
     *          Default 0, no restriction.
71
     */
72
    protected $maxUploadSize = 0;
73
74
    /**
75
     * TusServer constructor.
76
     *
77
     * @param Cacheable|string $cacheAdapter
78
     */
79 3
    public function __construct($cacheAdapter = 'file')
80
    {
81 3
        $this->request   = new Request;
82 3
        $this->response  = new Response;
83 3
        $this->uploadDir = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'uploads';
84
85 3
        $this->globalHeaders = [
86 3
            'Access-Control-Allow-Origin' => $this->request->header('Origin'),
87 3
            'Access-Control-Allow-Methods' => implode(',', $this->getRequest()->allowedHttpVerbs()),
88 3
            'Access-Control-Allow-Headers' => 'Origin, X-Requested-With, Content-Type, Content-Length, Upload-Key, Upload-Checksum, Upload-Length, Upload-Offset, Tus-Version, Tus-Resumable, Upload-Metadata',
89 3
            'Access-Control-Expose-Headers' => 'Upload-Key, Upload-Checksum, Upload-Length, Upload-Offset, Upload-Metadata, Tus-Version, Tus-Resumable, Tus-Extension, Location',
90 3
            'Access-Control-Max-Age' => self::HEADER_ACCESS_CONTROL_MAX_AGE,
91 3
            'X-Content-Type-Options' => 'nosniff',
92
        ];
93
94 3
        $this->setCache($cacheAdapter);
95 3
    }
96
97
    /**
98
     * Set upload dir.
99
     *
100
     * @param string $path
101
     *
102
     * @return Server
103
     */
104 2
    public function setUploadDir(string $path) : self
105
    {
106 2
        $this->uploadDir = $path;
107
108 2
        return $this;
109
    }
110
111
    /**
112
     * Get upload dir.
113
     *
114
     * @return string
115
     */
116 1
    public function getUploadDir() : string
117
    {
118 1
        return $this->uploadDir;
119
    }
120
121
    /**
122
     * Get request.
123
     *
124
     * @return Request
125
     */
126 1
    public function getRequest() : Request
127
    {
128 1
        return $this->request;
129
    }
130
131
    /**
132
     * Get request.
133
     *
134
     * @return Response
135
     */
136 1
    public function getResponse() : Response
137
    {
138 1
        return $this->response;
139
    }
140
141
    /**
142
     * Get file checksum.
143
     *
144
     * @param string $filePath
145
     *
146
     * @return string
147
     */
148 1
    public function getServerChecksum(string $filePath) : string
149
    {
150 1
        return hash_file($this->getChecksumAlgorithm(), $filePath);
151
    }
152
153
    /**
154
     * Get checksum algorithm.
155
     *
156
     * @return string|null
157
     */
158 1
    public function getChecksumAlgorithm()
159
    {
160 1
        $checksumHeader = $this->getRequest()->header('Upload-Checksum');
161
162 1
        if (empty($checksumHeader)) {
163 1
            return self::DEFAULT_CHECKSUM_ALGORITHM;
164
        }
165
166 1
        list($checksumAlgorithm) = explode(' ', $checksumHeader);
167
168 1
        return $checksumAlgorithm;
169
    }
170
171
    /**
172
     * Set upload key.
173
     *
174
     * @param string $key
175
     *
176
     * @return Server
177
     */
178 1
    public function setUploadKey(string $key) : self
179
    {
180 1
        $this->uploadKey = $key;
181
182 1
        return $this;
183
    }
184
185
    /**
186
     * Get upload key from header.
187
     *
188
     * @return string|HttpResponse
189
     */
190 4
    public function getUploadKey()
191
    {
192 4
        if ( ! empty($this->uploadKey)) {
193 1
            return $this->uploadKey;
194
        }
195
196 3
        $key = $this->getRequest()->header('Upload-Key') ?? Uuid::uuid4()->toString();
197
198 3
        if (empty($key)) {
199 1
            return $this->response->send(null, HttpResponse::HTTP_BAD_REQUEST);
200
        }
201
202 2
        $this->uploadKey = $key;
203
204 2
        return $this->uploadKey;
205
    }
206
207
    /**
208
     * Set max upload size.
209
     *
210
     * @param int $uploadSize
211
     *
212
     * @return Server
213
     */
214 2
    public function setMaxUploadSize(int $uploadSize) : self
215
    {
216 2
        $this->maxUploadSize = $uploadSize;
217
218 2
        return $this;
219
    }
220
221
    /**
222
     * Get max upload size.
223
     *
224
     * @return int
225
     */
226 1
    public function getMaxUploadSize() : int
227
    {
228 1
        return $this->maxUploadSize;
229
    }
230
231
    /**
232
     * Set or get global headers.
233
     *
234
     * @param array $headers
235
     *
236
     * @return Server|array
237
     */
238 1
    public function headers(array $headers = [])
239
    {
240 1
        if (empty($headers)) {
241 1
            return $this->globalHeaders;
242
        }
243
244 1
        $this->globalHeaders = $headers + $this->globalHeaders;
245
246 1
        return $this;
247
    }
248
249
    /**
250
     * Handle all HTTP request.
251
     *
252
     * @return HttpResponse
253
     */
254 3
    public function serve() : HttpResponse
255
    {
256 3
        $requestMethod = $this->getRequest()->method();
257 3
        $globalHeaders = $this->headers();
258
259 3
        if (HttpRequest::METHOD_OPTIONS !== $requestMethod) {
260 3
            $globalHeaders += ['Tus-Resumable' => self::TUS_PROTOCOL_VERSION];
261
        }
262
263
        // Allow overriding the HTTP method. The reason for this is
264
        // that some libraries/environments do not support PATCH and
265
        // DELETE requests, e.g. Flash in a browser and parts of Java.
266 3
        $newMethod = $this->getRequest()->header('X-HTTP-Method-Override');
267
268 3
        if ( ! empty($newMethod)) {
269 1
            $requestMethod = $newMethod;
270
        }
271
272 3
        if ( ! in_array($requestMethod, $this->getRequest()->allowedHttpVerbs())) {
273 1
            return $this->response->send(null, HttpResponse::HTTP_METHOD_NOT_ALLOWED);
274
        }
275
276 2
        $this->getResponse()->setHeaders($globalHeaders);
277
278 2
        $method = 'handle' . ucfirst(strtolower($requestMethod));
279
280 2
        return $this->{$method}();
281
    }
282
283
    /**
284
     * Handle OPTIONS request.
285
     *
286
     * @return HttpResponse
287
     */
288 2
    protected function handleOptions() : HttpResponse
289
    {
290
        $headers = [
291 2
            'Allow' => implode(',', $this->request->allowedHttpVerbs()),
292 2
            'Tus-Version' => self::TUS_PROTOCOL_VERSION,
293 2
            'Tus-Extension' => implode(',', self::TUS_EXTENSIONS),
294 2
            'Tus-Checksum-Algorithm' => $this->getSupportedHashAlgorithms(),
295
        ];
296
297 2
        $maxUploadSize = $this->getMaxUploadSize();
298
299 2
        if ($maxUploadSize > 0) {
300 1
            $headers['Tus-Max-Size'] = $maxUploadSize;
301
        }
302
303 2
        return $this->response->send(null, HttpResponse::HTTP_OK, $headers);
304
    }
305
306
    /**
307
     * Handle HEAD request.
308
     *
309
     * @return HttpResponse
310
     */
311 5
    protected function handleHead() : HttpResponse
312
    {
313 5
        $key = $this->request->key();
314
315 5
        if ( ! $fileMeta = $this->cache->get($key)) {
316 1
            return $this->response->send(null, HttpResponse::HTTP_NOT_FOUND);
317
        }
318
319 4
        $offset = $fileMeta['offset'] ?? false;
320
321 4
        if (false === $offset) {
322 1
            return $this->response->send(null, HttpResponse::HTTP_GONE);
323
        }
324
325 3
        return $this->response->send(null, HttpResponse::HTTP_OK, $this->getHeadersForHeadRequest($fileMeta));
326
    }
327
328
    /**
329
     * Handle POST request.
330
     *
331
     * @return HttpResponse
332
     */
333 5
    protected function handlePost() : HttpResponse
334
    {
335 5
        $fileName   = $this->getRequest()->extractFileName();
336 5
        $uploadType = self::UPLOAD_TYPE_NORMAL;
337
338 5
        if (empty($fileName)) {
339 1
            return $this->response->send(null, HttpResponse::HTTP_BAD_REQUEST);
340
        }
341
342 4
        if ( ! $this->verifyUploadSize()) {
343 1
            return $this->response->send(null, HttpResponse::HTTP_REQUEST_ENTITY_TOO_LARGE);
344
        }
345
346 3
        $uploadKey = $this->getUploadKey();
347 3
        $filePath  = $this->uploadDir . DIRECTORY_SEPARATOR . $fileName;
348
349 3
        if ($this->getRequest()->isFinal()) {
350 1
            return $this->handleConcatenation($fileName, $filePath);
351
        }
352
353 2
        if ($this->getRequest()->isPartial()) {
354 1
            $filePath   = $this->getPathForPartialUpload($uploadKey) . $fileName;
355 1
            $uploadType = self::UPLOAD_TYPE_PARTIAL;
356
        }
357
358 2
        $checksum = $this->getClientChecksum();
359 2
        $location = $this->getRequest()->url() . $this->getApiPath() . '/' . $uploadKey;
360
361 2
        $file = $this->buildFile([
362 2
            'name' => $fileName,
363 2
            'offset' => 0,
364 2
            'size' => $this->getRequest()->header('Upload-Length'),
365 2
            'file_path' => $filePath,
366 2
            'location' => $location,
367 2
        ])->setChecksum($checksum);
368
369 2
        $this->cache->set($uploadKey, $file->details() + ['upload_type' => $uploadType]);
370
371 2
        return $this->response->send(
372 2
            ['data' => ['checksum' => $checksum]],
373 2
            HttpResponse::HTTP_CREATED,
374
            [
375 2
                'Location' => $location,
376 2
                'Upload-Expires' => $this->cache->get($uploadKey)['expires_at'],
377
            ]
378
        );
379
    }
380
381
    /**
382
     * Handle file concatenation.
383
     *
384
     * @param string $fileName
385
     * @param string $filePath
386
     *
387
     * @return HttpResponse
388
     */
389 2
    protected function handleConcatenation(string $fileName, string $filePath) : HttpResponse
390
    {
391 2
        $partials  = $this->getRequest()->extractPartials();
392 2
        $uploadKey = $this->getUploadKey();
393 2
        $files     = $this->getPartialsMeta($partials);
394 2
        $filePaths = array_column($files, 'file_path');
395 2
        $location  = $this->getRequest()->url() . $this->getApiPath() . '/' . $uploadKey;
396
397 2
        $file = $this->buildFile([
398 2
            'name' => $fileName,
399 2
            'offset' => 0,
400 2
            'size' => 0,
401 2
            'file_path' => $filePath,
402 2
            'location' => $location,
403 2
        ])->setFilePath($filePath);
404
405 2
        $file->setOffset($file->merge($files));
406
407
        // Verify checksum.
408 2
        $checksum = $this->getServerChecksum($filePath);
409
410 2
        if ($checksum !== $this->getClientChecksum()) {
411 1
            return $this->response->send(null, self::HTTP_CHECKSUM_MISMATCH);
412
        }
413
414 1
        $this->cache->set($uploadKey, $file->details() + ['upload_type' => self::UPLOAD_TYPE_FINAL]);
415
416
        // Cleanup.
417 1
        if ($file->delete($filePaths, true)) {
418 1
            $this->cache->deleteAll($partials);
419
        }
420
421 1
        return $this->response->send(
422 1
            ['data' => ['checksum' => $checksum]],
423 1
            HttpResponse::HTTP_CREATED,
424
            [
425 1
                'Location' => $location,
426
            ]
427
        );
428
    }
429
430
    /**
431
     * Handle PATCH request.
432
     *
433
     * @return HttpResponse
434
     */
435 7
    protected function handlePatch() : HttpResponse
436
    {
437 7
        $uploadKey = $this->request->key();
438
439 7
        if ( ! $meta = $this->cache->get($uploadKey)) {
440 1
            return $this->response->send(null, HttpResponse::HTTP_GONE);
441
        }
442
443 6
        if (self::UPLOAD_TYPE_FINAL === $meta['upload_type']) {
444 1
            return $this->response->send(null, HttpResponse::HTTP_FORBIDDEN);
445
        }
446
447 5
        $file     = $this->buildFile($meta);
448 5
        $checksum = $meta['checksum'];
449
450
        try {
451 5
            $fileSize = $file->getFileSize();
452 5
            $offset   = $file->setKey($uploadKey)->setChecksum($checksum)->upload($fileSize);
453
454
            // If upload is done, verify checksum.
455 2
            if ($offset === $fileSize && ! $this->verifyChecksum($checksum, $meta['file_path'])) {
456 2
                return $this->response->send(null, self::HTTP_CHECKSUM_MISMATCH);
457
            }
458 3
        } catch (FileException $e) {
459 1
            return $this->response->send($e->getMessage(), HttpResponse::HTTP_UNPROCESSABLE_ENTITY);
460 2
        } catch (OutOfRangeException $e) {
461 1
            return $this->response->send(null, HttpResponse::HTTP_REQUESTED_RANGE_NOT_SATISFIABLE);
462 1
        } catch (ConnectionException $e) {
463 1
            return $this->response->send(null, HttpResponse::HTTP_CONTINUE);
464
        }
465
466 1
        return $this->response->send(null, HttpResponse::HTTP_NO_CONTENT, [
467 1
            'Content-Type' => 'application/offset+octet-stream',
468 1
            'Upload-Expires' => $this->cache->get($uploadKey)['expires_at'],
469 1
            'Upload-Offset' => $offset,
470
        ]);
471
    }
472
473
    /**
474
     * Handle GET request.
475
     *
476
     * @return BinaryFileResponse|HttpResponse
477
     */
478 4
    protected function handleGet()
479
    {
480 4
        $key = $this->request->key();
481
482 4
        if (empty($key)) {
483 1
            return $this->response->send('400 bad request.', HttpResponse::HTTP_BAD_REQUEST);
484
        }
485
486 3
        if ( ! $fileMeta = $this->cache->get($key)) {
487 1
            return $this->response->send('404 upload not found.', HttpResponse::HTTP_NOT_FOUND);
488
        }
489
490 2
        $resource = $fileMeta['file_path'] ?? null;
491 2
        $fileName = $fileMeta['name'] ?? null;
492
493 2
        if ( ! $resource || ! file_exists($resource)) {
494 1
            return $this->response->send('404 upload not found.', HttpResponse::HTTP_NOT_FOUND);
495
        }
496
497 1
        return $this->response->download($resource, $fileName);
498
    }
499
500
    /**
501
     * Handle DELETE request.
502
     *
503
     * @return HttpResponse
504
     */
505 3
    protected function handleDelete() : HttpResponse
506
    {
507 3
        $key      = $this->request->key();
508 3
        $fileMeta = $this->cache->get($key);
509 3
        $resource = $fileMeta['file_path'] ?? null;
510
511 3
        if ( ! $resource) {
512 1
            return $this->response->send(null, HttpResponse::HTTP_NOT_FOUND);
513
        }
514
515 2
        $isDeleted = $this->cache->delete($key);
516
517 2
        if ( ! $isDeleted || ! file_exists($resource)) {
518 1
            return $this->response->send(null, HttpResponse::HTTP_GONE);
519
        }
520
521 1
        unlink($resource);
522
523 1
        return $this->response->send(null, HttpResponse::HTTP_NO_CONTENT, [
524 1
            'Tus-Extension' => self::TUS_EXTENSION_TERMINATION,
525
        ]);
526
    }
527
528
    /**
529
     * Get required headers for head request.
530
     *
531
     * @param array $fileMeta
532
     *
533
     * @return array
534
     */
535 4
    protected function getHeadersForHeadRequest(array $fileMeta) : array
536
    {
537
        $headers = [
538 4
            'Upload-Length' => (int) $fileMeta['size'],
539 4
            'Upload-Offset' => (int) $fileMeta['offset'],
540 4
            'Cache-Control' => 'no-store',
541
        ];
542
543 4
        if (self::UPLOAD_TYPE_FINAL === $fileMeta['upload_type'] && $fileMeta['size'] !== $fileMeta['offset']) {
544 2
            unset($headers['Upload-Offset']);
545
        }
546
547 4
        if (self::UPLOAD_TYPE_NORMAL !== $fileMeta['upload_type']) {
548 3
            $headers += ['Upload-Concat' => $fileMeta['upload_type']];
549
        }
550
551 4
        return $headers;
552
    }
553
554
    /**
555
     * Build file object.
556
     *
557
     * @param array $meta
558
     *
559
     * @return File
560
     */
561 1
    protected function buildFile(array $meta) : File
562
    {
563 1
        $file = new File($meta['name'], $this->cache);
564
565 1
        if (array_key_exists('offset', $meta)) {
566 1
            $file->setMeta($meta['offset'], $meta['size'], $meta['file_path'], $meta['location']);
567
        }
568
569 1
        return $file;
570
    }
571
572
    /**
573
     * Get list of supported hash algorithms.
574
     *
575
     * @return string
576
     */
577 1
    protected function getSupportedHashAlgorithms() : string
578
    {
579 1
        $supportedAlgorithms = hash_algos();
580
581 1
        $algorithms = [];
582 1
        foreach ($supportedAlgorithms as $hashAlgo) {
583 1
            if (false !== strpos($hashAlgo, ',')) {
584 1
                $algorithms[] = "'{$hashAlgo}'";
585
            } else {
586 1
                $algorithms[] = $hashAlgo;
587
            }
588
        }
589
590 1
        return implode(',', $algorithms);
591
    }
592
593
    /**
594
     * Verify and get upload checksum from header.
595
     *
596
     * @return string|HttpResponse
597
     */
598 4
    protected function getClientChecksum()
599
    {
600 4
        $checksumHeader = $this->getRequest()->header('Upload-Checksum');
601
602 4
        if (empty($checksumHeader)) {
603 1
            return '';
604
        }
605
606 3
        list($checksumAlgorithm, $checksum) = explode(' ', $checksumHeader);
607
608 3
        $checksum = base64_decode($checksum);
609
610 3
        if ( ! in_array($checksumAlgorithm, hash_algos()) || false === $checksum) {
611 2
            return $this->response->send(null, HttpResponse::HTTP_BAD_REQUEST);
612
        }
613
614 1
        return $checksum;
615
    }
616
617
    /**
618
     * Get expired but incomplete uploads.
619
     *
620
     * @param array|null $contents
621
     *
622
     * @return bool
623
     */
624 3
    protected function isExpired($contents) : bool
625
    {
626 3
        $isExpired = empty($contents['expires_at']) || Carbon::parse($contents['expires_at'])->lt(Carbon::now());
627
628 3
        if ($isExpired && $contents['offset'] !== $contents['size']) {
629 3
            return true;
630
        }
631
632 2
        return false;
633
    }
634
635
    /**
636
     * Get path for partial upload.
637
     *
638
     * @param string $key
639
     *
640
     * @return string
641
     */
642 1
    protected function getPathForPartialUpload(string $key) : string
643
    {
644 1
        list($actualKey) = explode(self::PARTIAL_UPLOAD_NAME_SEPARATOR, $key);
645
646 1
        $path = $this->uploadDir . DIRECTORY_SEPARATOR . $actualKey . DIRECTORY_SEPARATOR;
647
648 1
        if ( ! file_exists($path)) {
649 1
            mkdir($path);
650
        }
651
652 1
        return $path;
653
    }
654
655
    /**
656
     * Get metadata of partials.
657
     *
658
     * @param array $partials
659
     *
660
     * @return array
661
     */
662 3
    protected function getPartialsMeta(array $partials) : array
663
    {
664 3
        $files = [];
665
666 3
        foreach ($partials as $partial) {
667 3
            $fileMeta = $this->getCache()->get($partial);
668
669 3
            $files[] = $fileMeta;
670
        }
671
672 3
        return $files;
673
    }
674
675
    /**
676
     * Delete expired resources.
677
     *
678
     * @return array
679
     */
680 2
    public function handleExpiration() : array
681
    {
682 2
        $deleted   = [];
683 2
        $cacheKeys = $this->cache->keys();
684
685 2
        foreach ($cacheKeys as $key) {
686 2
            $fileMeta = $this->cache->get($key, true);
687
688 2
            if ( ! $this->isExpired($fileMeta)) {
689 1
                continue;
690
            }
691
692 2
            if ( ! $this->cache->delete($key)) {
693 1
                continue;
694
            }
695
696 1
            if (is_writable($fileMeta['file_path'])) {
697 1
                unlink($fileMeta['file_path']);
698
            }
699
700 1
            $deleted[] = $fileMeta;
701
        }
702
703 2
        return $deleted;
704
    }
705
706
    /**
707
     * Verify max upload size.
708
     *
709
     * @return bool
710
     */
711 1
    protected function verifyUploadSize() : bool
712
    {
713 1
        $maxUploadSize = $this->getMaxUploadSize();
714
715 1
        if ($maxUploadSize > 0 && $this->getRequest()->header('Upload-Length') > $maxUploadSize) {
716 1
            return false;
717
        }
718
719 1
        return true;
720
    }
721
722
    /**
723
     * Verify checksum if available.
724
     *
725
     * @param string $checksum
726
     * @param string $filePath
727
     *
728
     * @return bool
729
     */
730 1
    protected function verifyChecksum(string $checksum, string $filePath) : bool
731
    {
732
        // Skip if checksum is empty.
733 1
        if (empty($checksum)) {
734 1
            return true;
735
        }
736
737 1
        return $checksum === $this->getServerChecksum($filePath);
738
    }
739
740
    /**
741
     * No other methods are allowed.
742
     *
743
     * @param string $method
744
     * @param array  $params
745
     *
746
     * @return HttpResponse|BinaryFileResponse
747
     */
748 1
    public function __call(string $method, array $params)
749
    {
750 1
        return $this->response->send(null, HttpResponse::HTTP_BAD_REQUEST);
751
    }
752
}
753