Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
die_coolen_jungs
our_own_cloud_project
Commits
7ad4dfa2
Commit
7ad4dfa2
authored
Mar 27, 2015
by
Vincent Petry
Browse files
Merge pull request #15227 from owncloud/ocetag-header
Copy Etag header to OC-Etag for sabre calls
parents
5aa81833
70acd583
Changes
3
Hide whitespace changes
Inline
Side-by-side
apps/files/appinfo/remote.php
View file @
7ad4dfa2
...
...
@@ -73,6 +73,7 @@ $server->on('beforeMethod', function () use ($server, $objectTree) {
)
)
);
$server
->
addPlugin
(
new
\
OC\Connector\Sabre\CopyEtagHeaderPlugin
());
},
30
);
// priority 30: after auth (10) and acl(20), before lock(50) and handling the request
// And off we go!
...
...
lib/private/connector/sabre/copyetagheaderplugin.php
0 → 100644
View file @
7ad4dfa2
<?php
/**
* ownCloud
*
* @author Vincent Petry
* @copyright 2015 Vincent Petry <pvince81@owncloud.com>
*
* @license AGPL3
*/
namespace
OC\Connector\Sabre
;
use
\
Sabre\HTTP\RequestInterface
;
use
\
Sabre\HTTP\ResponseInterface
;
/**
* Copies the "Etag" header to "OC-Etag" after any request.
* This is a workaround for setups that automatically strip
* or mangle Etag headers.
*/
class
CopyEtagHeaderPlugin
extends
\
Sabre\DAV\ServerPlugin
{
/**
* This initializes the plugin.
*
* @param \Sabre\DAV\Server $server Sabre server
*
* @return void
*/
public
function
initialize
(
\
Sabre\DAV\Server
$server
)
{
$server
->
on
(
'afterMethod'
,
array
(
$this
,
'afterMethod'
));
}
/**
* After method, copy the "Etag" header to "OC-Etag" header.
*
* @param RequestInterface $request request
* @param ResponseInterface $response response
*/
public
function
afterMethod
(
RequestInterface
$request
,
ResponseInterface
$response
)
{
$eTag
=
$response
->
getHeader
(
'Etag'
);
if
(
!
empty
(
$eTag
))
{
$response
->
setHeader
(
'OC-ETag'
,
$eTag
);
}
}
}
tests/lib/connector/sabre/copyetagheaderplugintest.php
0 → 100644
View file @
7ad4dfa2
<?php
namespace
Tests\Connector\Sabre
;
/**
* Copyright (c) 2015 Vincent Petry <pvince81@owncloud.com>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
class
CopyEtagPluginTest
extends
\
Test\TestCase
{
/**
* @var \OC\Connector\Sabre\CopyEtagHeaderPlugin
*/
private
$plugin
;
public
function
setUp
()
{
parent
::
setUp
();
$this
->
server
=
new
\
Sabre\DAV\Server
();
$this
->
plugin
=
new
\
OC\Connector\Sabre\CopyEtagHeaderPlugin
(
$this
->
tree
);
$this
->
plugin
->
initialize
(
$this
->
server
);
}
public
function
testCopyEtag
()
{
$request
=
new
\
Sabre\Http\Request
();
$response
=
new
\
Sabre\Http\Response
();
$response
->
setHeader
(
'Etag'
,
'abcd'
);
$this
->
plugin
->
afterMethod
(
$request
,
$response
);
$this
->
assertEquals
(
'abcd'
,
$response
->
getHeader
(
'OC-Etag'
));
}
public
function
testNoopWhenEmpty
()
{
$request
=
new
\
Sabre\Http\Request
();
$response
=
new
\
Sabre\Http\Response
();
$this
->
plugin
->
afterMethod
(
$request
,
$response
);
$this
->
assertNull
(
$response
->
getHeader
(
'OC-Etag'
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment