# Constile for Drupal The `constile` module serves the Constile offer to AI agents that fetch your articles for a person. People, search engines, and crawlers get your pages as usual. It runs the PHP gate from `integrations/php`. The module declares support for Drupal 10.1 and later, and Drupal 11. It was tested on Drupal 11.4. ## Install 1. Download `constile-drupal-0.6.0.zip` from your site page in the Constile dashboard. 2. Unzip it into `web/modules/custom/`, so the module is at `web/modules/custom/constile`. The zip bundles the gate library. 3. Turn the module on: `drush en constile`, or select it on the **Extend** page. 4. Go to **Configuration > Web services > Constile** (`/admin/config/services/constile`). Enter the site id, the site secret, and the network URL from your site page, then select **Save configuration**. The network URL must start with `https://`. 5. Select **Check install**. The module checks the settings, your site's seller file at its registered domain, and that its own requests reach Drupal with their bypass header. Then the network checks the install itself: it sends a one-time code to your site's `/.well-known/constile`, and the module confirms it with the site's credentials. If you manage the site with Composer, you can install the gate library with Composer instead (see `integrations/php/README.md`). The module then uses it instead of its bundled copy. ## Settings | Setting | Where it's kept | |---|---| | Site id, Network URL, Connect URL | Configuration (`constile.settings`), so they export with your config. | | Site secret | State, which doesn't export. To keep it out of the database, set `$settings['constile_secret']` in `settings.php`. | | Turn the gate off | State, from the checkbox on the settings form. Off, every request goes to Drupal unchanged. To set it without the form, put `$settings['constile_disabled'] = TRUE;` in `settings.php`, or `CONSTILE_DISABLED=1` in the server's environment. | The gate handles only requests for your site's registered domain, which the network's config names (or its `www.` twin), and passes every other request to Drupal untouched. Releases fetch the article from that domain. If the server can't reach its own public address, set **Connect URL**, such as `http://127.0.0.1`; the module still sends your domain as the host name. The visitor's address comes from Drupal, which honors the `reverse_proxy` settings in `settings.php`. If a load balancer or CDN sits in front of the site, set those. ## Paywalled content Gate 0.6.0 and later can fetch a paywalled article with the release instructions the network sends, so an agent gets the full text and the offer fits it. The network gives the gate a page address on your site's own host and, optionally, headers to send: `Cookie`, `Authorization`, `Constile-Paywall-Key`, or a header starting with `X-`. The gate ignores an address on another host and drops other headers. It strips `Set-Cookie` from what it releases and never logs the headers. To set up a method, open your site's page in the dashboard and choose a content API, a paywall rule, or a Constile login. A paywalled page gets offers only after the method works and the gate is 0.6.0 or later. ## How it works - The module adds an `http_middleware` service at priority 250. It runs after the reverse proxy middleware (300), and before the internal page cache (200), so an agent never gets a cached page. - It answers `/.well-known/constile` and `/sponsored/*` before routing. - For an agent, it gets the page from Drupal in process, then serves the offer instead. A person's request goes to Drupal untouched. - Requests with a Drupal session (signed-in users) pass through ungated, as the internal page cache treats them. Agents fetch anonymously. - Releases fetch the article over HTTP from your registered domain (at most two at once, 3 seconds each), without the agent's cookies, and carry a `Constile-Gate-Bypass` header with a random value made when you turn the module on. Requests with that value go to Drupal ungated. - When the network can't be reached, the module serves your pages as usual. A cache in front of Drupal, such as Varnish, a CDN, or your host's cache, can still serve a cached page to an agent. Ask whoever runs it to send requests whose `User-Agent` contains an agent token (such as `chatgpt-user` or `claude-user`) straight to Drupal. ## Run the test You need Docker. The test installs Drupal 11 with the standard profile on SQLite, installs the module from the release zip, and checks offers, the internal page cache, releases, the bypass, forged hosts, signed-in users, the settings form, and the install check: ```sh integrations/drupal/tests/run.sh ``` The first run downloads Drupal with Composer into the `constile-drupal` Docker volume.