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

Add missing checks in patch request [Fixes #96] #98

Merged
merged 14 commits into from
Oct 24, 2018

Conversation

DrudgeRajen
Copy link
Contributor

@DrudgeRajen DrudgeRajen commented Oct 23, 2018

  • All PATCH requests MUST use Content-Type: application/offset+octet-stream, otherwise the server SHOULD return a 415 Unsupported Media Type status.

  • If a PATCH request does not include a Content-Length header containing an integer value larger than 0, the server SHOULD return a 400 Bad Request status.

  • Test Coverage

@DrudgeRajen DrudgeRajen changed the title Issue fix/#96 [Issue fix/#96] Add missing checks in patch request #96 Oct 23, 2018
@@ -452,6 +452,14 @@ protected function sendPatchRequest(int $bytes, int $offset) : int
throw new ConnectionException('Connection aborted by user.');
}

if (HttpResponse::HTTP_UNSUPPORTED_MEDIA_TYPE == $statusCode) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use strict type check please ===

@@ -452,6 +452,14 @@ protected function sendPatchRequest(int $bytes, int $offset) : int
throw new ConnectionException('Connection aborted by user.');
}

if (HttpResponse::HTTP_UNSUPPORTED_MEDIA_TYPE == $statusCode) {
throw new ConnectionException('Unsupported media Types.');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not a connection exception. Can we use TusPhp\Exception please.

}

if (HttpResponse::HTTP_BAD_REQUEST === $statusCode) {
throw new ConnectionException('Bad request.');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above, not a connection exception

@@ -32,6 +32,9 @@ class Server extends AbstractTus
/** @const string Tus Concatenation Extension */
const TUS_EXTENSION_CONCATENATION = 'concatenation';

/** @const string Tus Content Type Extension */
const HEADER_CONTENT_TYPE = 'application/offset+octet-stream';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move this to AbstractTus class and use it in Client#L428 and Server#L464

$contentType = $this->request->header('Content-Type');
$contentLength = $this->request->header('Content-Length');

if ( ! $contentType || $contentType !== self::HEADER_CONTENT_TYPE) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first check ! $contentType is not necessary, second check will also be false in case $contentType is null or empty?

->getRequest()
->getRequest()
->headers
->set('Content-Length', 200);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of 2 set statements, we can use single add method to set headers at once

$this->tusServerMock
    ->getRequest()
    ->getRequest()
    ->headers
    ->add([
        'Content-Type' => 'application/offset+octet-stream',
        'Content-Length' => 200,
    ]);

->getRequest()
->getRequest()
->headers
->set('Content-Length', 200);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

->getRequest()
->getRequest()
->headers
->set('Content-Length', 200);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

@ankitpokhrel
Copy link
Owner

@ankitpokhrel ankitpokhrel merged commit 460f00c into ankitpokhrel:master Oct 24, 2018
@DrudgeRajen DrudgeRajen deleted the issue-fix/#96 branch October 24, 2018 15:05
@@ -454,6 +454,10 @@ protected function sendPatchRequest(int $bytes, int $offset) : int
throw new ConnectionException('Connection aborted by user.');
}

if (HttpResponse::HTTP_UNSUPPORTED_MEDIA_TYPE === $statusCode) {
throw new Exception('Unsupported media Types.');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it was going to be changed to TusException?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is already from Tus\Exception namespace, we just need to rename it to TusException to avoid confusion

@ankitpokhrel ankitpokhrel changed the title [Issue fix/#96] Add missing checks in patch request #96 Add missing checks in patch request [Fixes #96] Nov 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants