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

Adding the HEAD command #33

Merged
merged 7 commits into from Nov 20, 2017
Merged

Conversation

elabz
Copy link
Contributor

@elabz elabz commented Nov 15, 2017

Hi Robin, sorry this PR is a bit rushed. Unit tests are not my strong point, tho I could add the test for HeadCommand in time. Perhaps you might want to take a look at the implementation before we test anyway. Let me know if you have comments / suggestions
Cheers,
D.

public function onHeadFollows(MultiLineResponse $response)
{
$headers = [];
array_map(function ($line) use (&$headers) {
Copy link
Owner

Choose a reason for hiding this comment

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

Could you please make an array_reduce of this?

return array_reduce($response->getLines(), function ($headers, $line) {
    // if-statement here
    return $headers
})

@robinvdvleuten
Copy link
Owner

Thanks @elabz for your PR! Looks good to me 👍 Only a small comment on the code though. If you could change that + adding unit tests?

@@ -52,15 +52,14 @@ public function __invoke()
*/
public function onHeadFollows(MultiLineResponse $response)
{
$headers = [];
array_map(function ($line) use (&$headers) {
return array_reduce($response->getLines(), function ($headers, $line) {
preg_match('/^([^\:]+)\:\s*(.*)$/', $line, $matches);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, we do seem to have a genuine problem with multi-line fields within multi-line responses. news.php.net may be quite a bit busier than most, but they seem to have spliced super-long lines with \n\t ins some cases and \n\s in others.
Have you seen a lot of those spliced super-long lines out there in the wild? Any ideas on how to address that issue (if it indeed needs to be addressed)?
Thanks!

Choose a reason for hiding this comment

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

It may be safer to return the head as a string like the pear nntp class does and leave the name/value pair parsing to a wrapper class as not all users will need the data converted like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough @thebandit , I will refactor. Will leave the parsing of the full header to the application. It will essentially become a twin of the body command

Choose a reason for hiding this comment

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

Well see what @robinvdvleuten has to say as it's his project (I'm just an end-user like yourself). I was just offering a suggestion as it looks like this project tries to mimic the output of the pear class when possible.

@elabz
Copy link
Contributor Author

elabz commented Nov 19, 2017

@robinvdvleuten , I am just curious if the two failing tests (appveyor, styleci) were supposed to pass - the errors don't appear to be related to what I've added. If you see otherwise, please advise.

@robinvdvleuten
Copy link
Owner

@elabz they are indeed unrelated to your PR. The StyleCI fixes need to be applied by me and the AppVeyor is failing because of some weird Windows issue I need to look in to.

@robinvdvleuten
Copy link
Owner

@elabz thanks for the effort! I'll merge it in 👍

@robinvdvleuten robinvdvleuten merged commit 604c4bb into robinvdvleuten:master Nov 20, 2017
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