Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion components/ILIAS/DI/tests/HTTPServicesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

namespace ILIAS\DI;

use ILIAS\HTTP\Cookies\CookieFactory;
use ILIAS\HTTP\Cookies\CookieJarFactory;
use ILIAS\HTTP\Services;
use ILIAS\HTTP\Request\RequestFactory;
Expand Down Expand Up @@ -80,7 +81,7 @@ protected function setUp(): void

$this->mockDurationFactory = $this->createMock(DurationFactory::class);

$this->httpState = new RawHTTPServices($this->mockSenderStrategy, $this->mockCookieJarFactory, $this->mockRequestFactory, $this->mockResponseFactory, $this->mockDurationFactory);
$this->httpState = new RawHTTPServices($this->mockSenderStrategy, $this->mockCookieJarFactory, $this->mockRequestFactory, $this->mockResponseFactory, $this->mockDurationFactory, $this->createMock(CookieFactory::class));
}


Expand Down
78 changes: 0 additions & 78 deletions components/ILIAS/GlobalScreen/src/Client/ModeToggle.php

This file was deleted.

9 changes: 8 additions & 1 deletion components/ILIAS/HTTP/HTTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
use ILIAS\HTTP\Duration\Increment\IncrementFactory;
use ILIAS\HTTP\Response\ResponseFactory;
use ILIAS\HTTP\Cookies\CookieJarFactory;
use ILIAS\HTTP\Cookies\CookieFactory;
use ILIAS\HTTP\Cookies\CookieFactoryImpl;
use ILIAS\HTTP\Response\Sender\ResponseSenderStrategy;
use ILIAS\HTTP\Request\HeaderSettings;
use ILIAS\HTTP\Request\HeaderSettingsFromIni;
Expand All @@ -59,6 +61,7 @@ public function init(
$define[] = RequestFactory::class;
$define[] = ResponseFactory::class;
$define[] = CookieJarFactory::class;
$define[] = CookieFactory::class;
$define[] = GlobalHttpState::class;
$define[] = HeaderSettings::class;
$define[] = HttpPathProvider::class;
Expand All @@ -83,6 +86,9 @@ public function init(
// RESPONSE FACTORY
$implement[ResponseFactory::class] = static fn() => new ResponseFactoryImpl();

// COOKIE FACTORY
$implement[CookieFactory::class] = static fn() => new CookieFactoryImpl();

// COOKIE JAR FACTORY
$implement[CookieJarFactory::class] = static fn() => new CookieJarFactoryImpl();

Expand All @@ -100,7 +106,8 @@ public function init(
$use[ResponseFactory::class],
$use[CookieJarFactory::class],
$internal[ResponseSenderStrategy::class],
$internal[DurationFactory::class]
$internal[DurationFactory::class],
$use[CookieFactory::class]
);

// postMessage channel for pages talking to content of another origin, see README
Expand Down
23 changes: 14 additions & 9 deletions components/ILIAS/HTTP/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,20 @@ and can render the newly set cookies back.
Be aware that the cookie jar reads the cookies at creation time of the jar.
After the new cookie header is rendered into the response the response must be saved.
See the caveats section of the response for further information.

Cookies and cookie jars are immutable as well: every `with*()` returns a new instance, which
has to be used further on.

Cookies are created with the `CookieFactory` of the HTTP services (`$dic->http()->cookies()`,
or `$use[\ILIAS\HTTP\Cookies\CookieFactory::class]` in a component bootstrap). Components
MUST NOT instantiate the implementations (`CookieFactoryImpl`, `CookieWrapper`, ...) or use the
underlying library (`Dflydev\FigCookies\*`) directly.

### Usage

#### Add new Cookie
```php
<?php
use \ILIAS\HTTP\Cookies\CookieFactoryImpl;
use \ILIAS\HTTP\Cookies\CookieJar;

//get the cookie jar
Expand All @@ -141,14 +148,14 @@ $dic = $GLOBALS["DIC"];
*/
$cookieJar = $dic->http()->cookieJar();

//create a new cookie factory
$cookieFactory = new CookieFactoryImpl();
//get the cookie factory
$cookieFactory = $dic->http()->cookies();

//create a cookie
$cookie = $cookieFactory->create("CookieName", "CookieValue");

//set the cookie path
$cookie->withPath('/');
$cookie = $cookie->withPath('/');

//render the cookies back into the response.
$response = $cookieJar
Expand All @@ -163,7 +170,6 @@ $dic->http()->saveResponse($response);

```php
<?php
use \ILIAS\HTTP\Cookies\CookieFactoryImpl;
use \ILIAS\HTTP\Cookies\CookieJar;

//get the cookie jar
Expand All @@ -174,15 +180,14 @@ $dic = $GLOBALS["DIC"];
*/
$cookieJar = $dic->http()->cookieJar();

//create a new cookie factory
$cookieFactory = new CookieFactoryImpl();
//get the cookie factory
$cookieFactory = $dic->http()->cookies();

//create an expired cookie
$cookie = $cookieFactory->createExpired("CookieName");

//set the cookie path
$cookie
->withPath('/');
$cookie = $cookie->withPath('/');

//render the cookies back into the response.
$response = $cookieJar
Expand Down
1 change: 1 addition & 0 deletions components/ILIAS/HTTP/src/Cookies/CookieJarWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*
* Wrapper class for the FigCookies SetCookies class.
*
* @internal Create cookies with {@see CookieFactory} and cookie jars with {@see CookieJarFactory}.
* @author Nicolas Schäfli <ns@studer-raimann.ch>
* @package ILIAS\HTTP\Cookies
* @since 5.3
Expand Down
1 change: 1 addition & 0 deletions components/ILIAS/HTTP/src/Cookies/CookieWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
/**
* Class CookieWrapper
* Facade class for the FigCookies SetCookie class.
* @internal Create cookies with {@see CookieFactory} and cookie jars with {@see CookieJarFactory}.
* @author Nicolas Schäfli <ns@studer-raimann.ch>
* @package ILIAS\HTTP\Cookies
* @since 5.3
Expand Down
6 changes: 6 additions & 0 deletions components/ILIAS/HTTP/src/GlobalHttpState.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
namespace ILIAS\HTTP;

use ILIAS\HTTP\Cookies\CookieJar;
use ILIAS\HTTP\Cookies\CookieFactory;
use ILIAS\HTTP\Response\Sender\ResponseSendingException;
use ILIAS\HTTP\Wrapper\WrapperFactory;
use Psr\Http\Message\RequestInterface;
Expand Down Expand Up @@ -67,6 +68,11 @@ public function response(): ResponseInterface;
*/
public function cookieJar(): CookieJar;

/**
* Creates cookies, which are added to the response with {@see self::cookieJar()}.
*/
public function cookies(): CookieFactory;


/**
* Saves the given request for further use.
Expand Down
9 changes: 8 additions & 1 deletion components/ILIAS/HTTP/src/RawHTTPServices.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

namespace ILIAS\HTTP;

use ILIAS\HTTP\Cookies\CookieFactory;
use ILIAS\HTTP\Cookies\CookieJar;
use ILIAS\HTTP\Cookies\CookieJarFactory;
use ILIAS\HTTP\Request\RequestFactory;
Expand All @@ -44,7 +45,8 @@ public function __construct(
private CookieJarFactory $cookieJarFactory,
private RequestFactory $requestFactory,
private ResponseFactory $responseFactory,
private DurationFactory $durationFactory
private DurationFactory $durationFactory,
private CookieFactory $cookieFactory
) {
}

Expand All @@ -67,6 +69,11 @@ public function wrapper(): WrapperFactory
/**
* @inheritDoc
*/
public function cookies(): CookieFactory
{
return $this->cookieFactory;
}

public function cookieJar(): CookieJar
{
return $this->cookieJarFactory->fromResponse($this->response());
Expand Down
10 changes: 9 additions & 1 deletion components/ILIAS/HTTP/src/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

namespace ILIAS\HTTP;

use ILIAS\HTTP\Cookies\CookieFactory;
use ILIAS\HTTP\Cookies\CookieJar;
use ILIAS\HTTP\Wrapper\WrapperFactory;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -52,13 +53,15 @@ public function __construct(
CookieJarFactory $cookie_jar,
ResponseSenderStrategy $response_sender_strategy,
DurationFactory $duration_factory,
CookieFactory $cookie_factory,
) {
$this->raw = new RawHTTPServices(
$response_sender_strategy,
$cookie_jar,
$request_factory,
$response_factory,
$duration_factory
$duration_factory,
$cookie_factory
);
$this->agent = new AgentDetermination();
}
Expand Down Expand Up @@ -112,6 +115,11 @@ public function response(): ResponseInterface
* @see Services::wrapper();
* @inheritDoc
*/
public function cookies(): CookieFactory
{
return $this->raw->cookies();
}

public function cookieJar(): CookieJar
{
return $this->raw()->cookieJar();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*
*********************************************************************/

use ILIAS\HTTP\Cookies\CookieFactoryImpl;
use ILIAS\HTTP\Cookies\CookieFactory;
use ILIAS\DI\Container;
use ILIAS\HTTP\Request\RequestFactoryImpl;
use ILIAS\HTTP\Response\ResponseFactoryImpl;
Expand Down Expand Up @@ -49,6 +51,8 @@ public function init(Container $container): void

$container[ResponseFactory::class] = static fn($c): ResponseFactoryImpl => new ResponseFactoryImpl();

$container[CookieFactory::class] = static fn($c): CookieFactoryImpl => new CookieFactoryImpl();

$container[CookieJarFactory::class] = static fn($c): CookieJarFactoryImpl => new CookieJarFactoryImpl();

$container[ResponseSenderStrategy::class] = static fn(
Expand All @@ -69,6 +73,7 @@ public function init(Container $container): void
$c[CookieJarFactory::class],
$c[ResponseSenderStrategy::class],
$c[DurationFactory::class],
$c[CookieFactory::class],
);
$container['http'] = static fn($c): Services => $c[GlobalHttpState::class];
}
Expand Down
3 changes: 0 additions & 3 deletions components/ILIAS/User/service.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,5 @@
<cron id="user_check_accounts" class="ilUserCronCheckAccounts" />
<cron id="user_never_logged_in" class="ilCronDeleteNeverLoggedInUserAccounts" />
</crons>
<web_access_checker>
<secure_path path="usr_images" checking-class="ilObjUserAccess" />
</web_access_checker>
<badges />
</service>
3 changes: 1 addition & 2 deletions components/ILIAS/Utilities/classes/class.ilUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

use ILIAS\FileDelivery\Delivery;
use ILIAS\Filesystem\Stream\Streams;
use ILIAS\HTTP\Cookies\CookieFactoryImpl;
use ILIAS\HTTP\Cookies\Cookie;

/**
Expand Down Expand Up @@ -1289,7 +1288,7 @@ public static function setCookie(
$http = $DIC->http();
$cookie_jar = $http->cookieJar();

$cookie_factory = new CookieFactoryImpl();
$cookie_factory = $http->cookies();

$cookie_expire = null;
if (defined('IL_COOKIE_EXPIRE') && is_numeric(IL_COOKIE_EXPIRE) && IL_COOKIE_EXPIRE > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

// declare(strict_types=1);
use ILIAS\HTTP\Cookies\CookieFactory;
use ILIAS\HTTP\Cookies\CookieFactoryImpl;
use ILIAS\WebAccessChecker\PathType;
use ILIAS\HTTP\GlobalHttpState;

Expand Down Expand Up @@ -219,7 +218,7 @@ public static function signFile(string $path_to_file): string
if ($ilWACPath->getClient() === '' || $ilWACPath->getClient() === '0') {
return $path_to_file;
}
$obj = new self($ilWACPath, $DIC->http(), new CookieFactoryImpl());
$obj = new self($ilWACPath, $DIC->http(), $DIC->http()->cookies());
$obj->setType(PathType::FILE);
$obj->buildAndSetTokenInstance(time(), self::getTokenMaxLifetimeInSeconds());

Expand All @@ -229,7 +228,7 @@ public static function signFile(string $path_to_file): string
public static function signFolderOfStartFile(string $start_file_path): void
{
global $DIC;
$obj = new self(new ilWACPath($start_file_path), $DIC->http(), new CookieFactoryImpl());
$obj = new self(new ilWACPath($start_file_path), $DIC->http(), $DIC->http()->cookies());
$obj->setType(PathType::FOLDER);
$obj->buildAndSetTokenInstance(time(), self::getCookieMaxLifetimeInSeconds());
$obj->saveFolderToken();
Expand Down
3 changes: 2 additions & 1 deletion components/ILIAS/WebAccessChecker/resources/wac.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
$c['http.cookie_jar_factory'],
$c['http.response_sender_strategy'],
$c['http.duration_factory'],
new CookieFactoryImpl(),
);

$GLOBALS["DIC"] = $container;
Expand All @@ -68,7 +69,7 @@
$Services = $container['http'];

//TODO: fix tests and mod_xsendfile which refuses to work
ilWebAccessCheckerDelivery::run($Services, new CookieFactoryImpl());
ilWebAccessCheckerDelivery::run($Services, $Services->cookies());

//send response
$Services->sendResponse();
Loading
Loading