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

[WIP] Use stream wrapper that allows to seek HTTP files #11000

Closed
wants to merge 4 commits into from
Closed

[WIP] Use stream wrapper that allows to seek HTTP files #11000

wants to merge 4 commits into from

Conversation

lokeller
Copy link

We want to start pushing to client connecting to owncloud the content of files stored on a remote DAV server while we are still downloading
it from the remote server without waiting to first fully download the file on the owncloud server. We cannot directly use fopen('http://...') because
we want to be able to seek the resource, instead we use the stream wrapper implemented here.

Some things on which feedback would be very useful:

  • is the wrapper implementing enough functions or some are missing?
  • what is the best way to create unit tests for this code?

@lokeller lokeller mentioned this pull request Sep 10, 2014
10 tasks
@ghost
Copy link

ghost commented Sep 10, 2014

Thanks a lot for your contribution! Contributions to the core repo require a signed contributors agreement http://owncloud.org/contribute/agreement/ Alternatively you can add a comment here stating that this contribution is MIT licensed. Some more details about out pull request workflow can be found here: http://owncloud.org/code-reviews-on-github/

@lokeller
Copy link
Author

This contribution is MIT licensed (one of the files is put in the public domain).

if ($this->certPath) {
curl_setopt($curl, CURLOPT_CAINFO, $this->certPath);
$url .= "&capath=" . urlencode($this->certPath);
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of messing with urlencoding it's a lot easier to pass all the options a stream context

@PVince81
Copy link
Contributor

@icewind1991 @bantu

@PVince81
Copy link
Contributor

We might want to add unit tests in tests/lib/files/storage/storage.php that test seeking on small and big files for all storage types.

@PVince81
Copy link
Contributor

@lokeller have you found how to run the external storage unit tests ?
Currently these need to be run manually, have a look at apps/files_external/tests/config.php where you need to enable WebDAV external storage testing with credentials, etc.

@PVince81
Copy link
Contributor

Only enable it locally, then run ./autotest.sh mysql ../apps/files_external/tests/webdav.php

@icewind1991
Copy link
Contributor

Wouldn't it be easier to wrap an existing http stream and make it seekable by buffering it

@lokeller
Copy link
Author

Wrapping an existing http stream would be for sure simpler and cleaner but I'm not sure how to handle this part:

curl_setopt($curl, CURLOPT_CAINFO, $args['capath']);

I need to do it to make the code functionally equivalent to what I'm substituting.

rewind($fp);
return $fp;
$params = array( 'seekablehttp' => $options );
error_log($params);
Copy link
Member

Choose a reason for hiding this comment

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

debug code - please remove

@DeepDiver1975
Copy link
Member

this code can only go in with a proper unit test - THX

@lokeller
Copy link
Author

@PVince81 thanks for the pointers to the unit testing stuff.

I will try to develop unit tests for this.

@PVince81
Copy link
Contributor

@icewind1991 any comment on #11000 (comment) ?

This needs rebase + unit tests.

@lokeller
Copy link
Author

I did a rebase but I didn't have time yet to work on the unit tests. These will come eventually :)

In external storage we want to start pushing to our clients the content
of files stored on a remote DAV server while we are downloading them from
the server but we also need to seek these files. For this reason we
cannot use fopen('http:/...') and instead we need a custom stream wrapper.
@lokeller
Copy link
Author

Addressed comment from @DeepDiver1975

@PVince81
Copy link
Contributor

Thanks 😄

return FALSE;
}

$available_count = min( $this->read_bytes - $this->position, $count);
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of returning "to little data" I would prefer to do $this->wait_for_position($this->position+$count)

@icewind1991
Copy link
Contributor

Could you use camelCase instead of underscores

@lokeller
Copy link
Author

Addressed easy comments. Still missing unit tests, I need to first understand how they work.

@scrutinizer-notifier
Copy link

The inspection completed: 53 new issues, 15 updated code elements

@LukasReschke LukasReschke changed the title Use stream wrapper that allows to seek HTTP files [WIP] Use stream wrapper that allows to seek HTTP files Feb 24, 2015
@ghost
Copy link

ghost commented Apr 30, 2015

Can one of the admins verify this patch?

@PVince81
Copy link
Contributor

@owncloud-bot ok to test

@PVince81
Copy link
Contributor

PVince81 commented Jul 3, 2015

@icewind1991 is this PR a good alternative to your older PR #10620 ?

@icewind1991
Copy link
Contributor

I would still prefer having a generic caching stream wrapper that takes an existing non-seekable stream and makes it seekable.

@PVince81
Copy link
Contributor

PVince81 commented Sep 1, 2015

Might be related #18653

@lokeller
Copy link
Author

lokeller commented Sep 2, 2015

Yes, the objective of my patch was the same as #18653 . The new implementation is clearly better because reuses code already present in the tree. I'm retracting my pull request.

@lokeller lokeller closed this Sep 2, 2015
@lock lock bot locked as resolved and limited conversation to collaborators Aug 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants