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

Better HTTP headers #2039

Merged

Conversation

jewome62
Copy link
Contributor

@jewome62 jewome62 commented Jun 25, 2018

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? yes, i add one
Tests pass? no, but i work on this
Fixed tickets #1912
License MIT
Doc PR none


public function __construct(DataPersisterInterface $dataPersister)
public function __construct(DataPersisterInterface $dataPersister, IriConverterInterface $iriConverter)
Copy link
Member

Choose a reason for hiding this comment

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

this is a BC break

Copy link
Contributor

Choose a reason for hiding this comment

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

The second argument must be made optional. 😄

But we can trigger a deprecation error if it's not provided.

Copy link
Member

Choose a reason for hiding this comment

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

haha sorry yeah I should've say what you said in addition 😆

'X-Frame-Options' => 'deny',
];

if($request->isMethod('POST') || $request->isMethod('PUT')){
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be the same for PATCH, I think...


public function __construct(DataPersisterInterface $dataPersister)
public function __construct(DataPersisterInterface $dataPersister, IriConverterInterface $iriConverter)
Copy link
Contributor

Choose a reason for hiding this comment

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

The second argument must be made optional. 😄

But we can trigger a deprecation error if it's not provided.

@@ -57,6 +60,7 @@ public function onKernelView(GetResponseForControllerResultEvent $event)
}

$event->setControllerResult($persistResult ?? $controllerResult);
$request->attributes->set('_iri_item', $this->iriConverter->getIriFromItem($controllerResult));
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe _api_write_item_iri?

@@ -25,10 +26,12 @@
class WriteListener
Copy link
Contributor

@teohhanhui teohhanhui Jun 25, 2018

Choose a reason for hiding this comment

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

Also, I think we could mark this class as final? It was never designed to be extended in the first place...

(Strictly speaking, it'd be a BC break... But I highly doubt it'd bother anyone. I don't remember if we've done something like this before. Do we just add the @final in PHPDoc?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

or @internal ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add @final in the PHPDoc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See #2046

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's leave this to #2046 then. 😄

@jewome62
Copy link
Contributor Author

jewome62 commented Jun 25, 2018

Hands Up!

OK OK, I confess, I fucked up, I did not think and I pushed my work not finished by putting WIP tag

DO NOT SHOOT ME ! I HAVE A WIFE AND CHILDREN !

;)

@jewome62 jewome62 force-pushed the feature/better-http-headers branch 3 times, most recently from 28621b0 to 5c8abe3 Compare June 25, 2018 20:05
@jewome62 jewome62 changed the title [WIP] Better HTTP headers Better HTTP headers Jun 25, 2018
@jewome62
Copy link
Contributor Author

@teohhanhui
All is good here,
The fail test became from last release of Symfony and affect master too

See: #2043

'X-Frame-Options' => 'deny',
];

if ($request->isMethod('POST') || $request->isMethod('PUT') || $request->isMethod('PATCH')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use \in_array here.

@@ -25,10 +26,12 @@
class WriteListener
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add @final in the PHPDoc.

@teohhanhui
Copy link
Contributor

The error messages need to be rephrased. I'll give some suggestions, if somebody doesn't get it done before I do.

$headers['Location'] = $request->attributes->get('_api_write_item_iri');
}
} else {
@trigger_error(sprintf('No request attribute from `_api_write_item_iri` key is deprecated since API Platform 2.3 and will not be supported in API Platform 3, an string should always be returned. see deprecated into %s constructor for more details.', WriteListener::class), E_USER_DEPRECATED);
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if we should have this deprecation error here, but:

Not setting the _api_write_item_iri request attribute is deprecated since API Platform 2.3 and will not be supported in API Platform 3. See %s for the default implementation.

@jewome62
Copy link
Contributor Author

@teohhanhui I make the fix.

Anyway, @dunglas said me that we are trying to reduce the dependencies in the Platform API classes, so normally I will remove the deprecated ones to make sure that it remains optional definitively.

Copy link
Contributor

@teohhanhui teohhanhui left a comment

Choose a reason for hiding this comment

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

Can you squash the commits? 😄

@@ -25,10 +26,12 @@
class WriteListener
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's leave this to #2046 then. 😄

@jewome62 jewome62 force-pushed the feature/better-http-headers branch 2 times, most recently from bd333a9 to d8a707d Compare June 28, 2018 13:11
@jewome62
Copy link
Contributor Author

I have rebase from master

@jewome62 jewome62 force-pushed the feature/better-http-headers branch from d8a707d to 592891e Compare June 28, 2018 13:47
@jewome62 jewome62 force-pushed the feature/better-http-headers branch from 592891e to d361494 Compare June 28, 2018 14:02
use ApiPlatform\Core\DataPersister\DataPersisterInterface;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;

/**
* Bridges persistense and the API system.
*
* @final
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be removed.

@jewome62 jewome62 force-pushed the feature/better-http-headers branch from d361494 to 7507d90 Compare June 28, 2018 14:06
@soyuka soyuka force-pushed the feature/better-http-headers branch 2 times, most recently from 66898c9 to 7f046fd Compare July 13, 2018 13:48
@soyuka
Copy link
Member

soyuka commented Jul 13, 2018

@dunglas may you merge this please? I rebased it.

@teohhanhui teohhanhui merged commit 797cea6 into api-platform:master Jul 19, 2018
@teohhanhui
Copy link
Contributor

Thanks @jewome62! 🎉

@jewome62 jewome62 deleted the feature/better-http-headers branch July 30, 2018 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants