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

Small fix for CHttpRequest to send valid content-length and output #1523

Merged
merged 7 commits into from
Nov 28, 2012
Merged

Small fix for CHttpRequest to send valid content-length and output #1523

merged 7 commits into from
Nov 28, 2012

Conversation

Ragazzo
Copy link

@Ragazzo Ragazzo commented Oct 3, 2012

For more info: issue #1279 and #1249

@cebe
Copy link
Member

cebe commented Oct 3, 2012

This reverts the fix for #1249. Can you explain how it solves #1279? They are also different issues that need separate handling, so what you are doing here is not the way to go.

Btw: use tab indentation, not spaces.

@cebe cebe closed this Oct 3, 2012
@cebe
Copy link
Member

cebe commented Oct 3, 2012

Seems you changed something while I was commenting, but still not okay.

@cebe cebe reopened this Oct 3, 2012
@ghost ghost assigned cebe Oct 3, 2012
@Ragazzo
Copy link
Author

Ragazzo commented Oct 3, 2012

As u can see in issue 1279 i was solving problem with valid content output like in issue 1249, but also in current version ob_get_length() will alwayse be false because of php.ini settings (buffer size), so i think this PR can solve this 2 problems, why do u think they are different? did u see 1279?
yes, did some changes, first PR in github, what is wrong with it on your thought?

@cebe
Copy link
Member

cebe commented Oct 3, 2012

did you understand what #1249 is about? it kills output genereated by Yii::app()->end(). So the code has to stay there.
They are definitively not the same issues.

@Ragazzo
Copy link
Author

Ragazzo commented Oct 3, 2012

Hm, yes, was wrong, so, maybe then leave ob_* near Yii::app()->end() and delete if ob_get_length() because this brokes valid content-length(no header in request) ? I was getting error with content when use some debug toolbar, so it was not using onEndRequest(just dumped data after all render) thats why i could not understand what u were talking about, now got it. What do u think about to remove the if check buffer length row?

@Ragazzo
Copy link
Author

Ragazzo commented Oct 3, 2012

@cebe made new PR with fixes from #1249 and no "if", is it ok?

@cebe
Copy link
Member

cebe commented Oct 3, 2012

You are still replacing CHANGELOG line, please add a new one for your issue.
Will check your fix later.

@Ragazzo
Copy link
Author

Ragazzo commented Oct 4, 2012

@cebe done, is it ok?

@Ragazzo
Copy link
Author

Ragazzo commented Oct 9, 2012

@cebe can u merge it, so i can use it in current master branch?

@cebe
Copy link
Member

cebe commented Oct 9, 2012

@Ragazzo will merge it when I find time to check it.

@@ -17,6 +17,7 @@ Version 1.1.13 work in progress
- Bug #1181: Fixed can read but not save binary data e.g. BYTEA on PostgreSQL (karmakaze)
- Bug #1212: Added missing .gitignore files to the application generated by WebAppCommand (resurtm)
- Bug #1249: CHttpRequest::sendFile() outputs malformed file content in some specific circumstances (andyhu)
- Bug #1279: CHttpRequest::sendFile() fixed valid content-header send (Ragazzo)
Copy link
Member

Choose a reason for hiding this comment

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

Better to descibe it like CHttpRequest::sendFile() now always sends valid content-header.

@Ragazzo
Copy link
Author

Ragazzo commented Oct 10, 2012

@samdark now ok. hm, is it wrong that "push" to my "repo" was displayed here, i am talking about "b80f229"?

@samdark
Copy link
Member

samdark commented Oct 11, 2012

It's expected. The branch you've pull-requested is tracked by github so when you'll do any changes these will be in the pull request automatically.

@cebe
Copy link
Member

cebe commented Nov 14, 2012

@samdark just seen that you added the line removed here in b029edc do you remember any details about the problem? Imo it should always send the Content-Length-header independent of output buffering, so I'd merge this PR but would be cool to know what problem was with output buffering to not re-introduce it now.

@cebe
Copy link
Member

cebe commented Nov 14, 2012

Oh, original code comes from 54a24af#L8L551 I am afraid we can't easily find the reason for the existence of this line.
@qiangxue @mdomba any idea?

@cebe
Copy link
Member

cebe commented Nov 14, 2012

Sorry for posting that much. Found the original issue: http://code.google.com/p/yii/issues/detail?id=788
Will re-check it.

@cebe
Copy link
Member

cebe commented Nov 14, 2012

I checked this code with the following actions:

    public function actionDownload()
    {
        Yii::app()->request->sendFile('testfile.txt', str_repeat('aslkdufzas87dfzaosdlfhjaosdiufza', 32)); // file size 1024
    }
    public function actionDownload()
    {
        ini_set("zlib.output_compression", "On");
        Yii::app()->request->sendFile('testfile.txt', str_repeat('aslkdufzas87dfzaosdlfhjaosdiufza', 32)); // file size 1024
    }
    public function actionDownload()
    {
        ob_start("ob_gzhandler");
        Yii::app()->request->sendFile('testfile.txt', str_repeat('aslkdufzas87dfzaosdlfhjaosdiufza', 32)); // file size 1024
    }

Checked with PHP 5.3.15 Chrome, Firefox, Opera, IE and Safari all working fine.
So I can't see a reason why if(ob_get_length()===false) should stay. We might need to check it for PHP 5.2.x, but I currently don't have that version available here.

@samdark
Copy link
Member

samdark commented Nov 14, 2012

@cebe this is to make sure all buffers are already flushed and no buffering is active. I think to see why it's there you have to either turn on output buffering in php.ini or set your custom handler for it.

@cebe
Copy link
Member

cebe commented Nov 14, 2012

@samdark I did the test with output_buffering On and the last action registers the ob_gzhandler which caused no problems with the Content-Length-Header. I can't reproduce the problem that made if(ob_get_length()===false) necessary with php 5.3. Maybe it only exists in php 5.2? would be cool if someone could check that.

@samdark
Copy link
Member

samdark commented Nov 14, 2012

Check #4

@cebe
Copy link
Member

cebe commented Nov 14, 2012

I've seen that and what I can tell is that the Content-Length header is fine even when and output handler is enabled. At least for php 5.3

@cebe cebe closed this Nov 14, 2012
@cebe cebe reopened this Nov 14, 2012
@samdark
Copy link
Member

samdark commented Nov 14, 2012

Hmm, there should be a reason. @qiangxue http://code.google.com/p/yii/source/detail?r=1822 seems to be your fix. Can you remember how to reproduce it?

@mdomba
Copy link
Member

mdomba commented Nov 15, 2012

@cebe
Copy link
Member

cebe commented Nov 27, 2012

@qiangxue can you comment on this? #1523 (comment) I'd like to have this fixed in 1.1.13

@qiangxue
Copy link
Member

I think it's because when there's output_handler, it is possible the output is compressed, and as a result the content length may not be the actual one.

@cebe
Copy link
Member

cebe commented Nov 28, 2012

As I said in this comment: #1523 (comment) I tested all common output handlers and they all give the correct output length.

@samdark
Copy link
Member

samdark commented Nov 28, 2012

If I remember, it was a kind of combination of ob_gz_handler set in php.ini and deflate. Something like https://bugs.php.net/bug.php?id=51898 but not quite so.

@samdark
Copy link
Member

samdark commented Nov 28, 2012

Anyway, if we can't figure out and it works currently with all possible combinations, I think we can fix not sending content-length in general and deal with consequences if there will be any during RC time.

@cebe
Copy link
Member

cebe commented Nov 28, 2012

ob_gz_handler and deflate isn't a combination that should be used in webserver config, so I think we should not add workarounds for it.
So I think we can merge this.

@samdark
Copy link
Member

samdark commented Nov 28, 2012

Agree. Better of two evils.

cebe added a commit that referenced this pull request Nov 28, 2012
Small fix for CHttpRequest to send valid content-length and output
@cebe cebe merged commit a0c5171 into yiisoft:master Nov 28, 2012
@cebe
Copy link
Member

cebe commented Nov 28, 2012

Thanks for working on this @Ragazzo!

@Ragazzo
Copy link
Author

Ragazzo commented Nov 28, 2012

@cebe hm, thank you and other core-developers for working on this one, more work was made by them, when discussing this solution. Anyway will do on weekend correct PR about "range-header" that was mentioned here, just learning the w3c docs about correct behavior of handling this situation.

This pull request was closed.
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.

5 participants