# Add Response Compression to an Actix Web App from a Linear Issue

Yes. An agent picks up the Linear issue, wraps your Actix Web app in the Compress middleware, tests gzip and brotli negotiation and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-compression/actix/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent starts from the issue text and the repository in its own cloud sandbox, and reads the server setup before it adds anything, because compression in Actix is a middleware whose position in the `wrap` chain decides what it sees. In an application like the `basics/todo` example in actix/examples, `Cargo.toml` takes `actix-web`, `actix-files` and `actix-session` from the workspace, where `actix-web = "4.11"` with its default features, plus `sqlx` 0.9 on SQLite and `tera` 2 for templates. `src/main.rs` builds the `App` with `web::Data` for the `Tera` templates and the `SqlitePool`, then `.wrap(Logger::default())`, `.wrap(session_store)` and `.wrap(error_handlers)`, and serves `/` from `api::index`, `/todo` and `/todo/{id}` as form posts, and `/static` through `actix_files::Files`. Every page is an HTML render from `templates/index.html.tera`, and `static/css` holds `normalize.css`, `skeleton.css` and `style.css`, all text that compresses well and all sent uncompressed today.

The change is small and the agent keeps it that way. It adds `.wrap(middleware::Compress::default())` to the `App` builder, placed so it wraps the responses the handlers and the static file service produce, and confirms in the workspace `Cargo.lock` that `brotli`, `flate2` and `zstd` are already resolved, which means `actix-web`'s default compression features are on and no new dependency is needed. `Compress::default()` negotiates from the request's `Accept-Encoding`, so a client that sends none gets the same bytes as before, and the error pages served by `api::bad_request`, `api::not_found` and `api::internal_server_error` through `NamedFile` go through the same middleware.

Tests use `actix_web::test`, the same way other examples in the workspace test their apps. The agent adds a test module to `src/main.rs` that builds the `App` with the middleware and a temporary SQLite pool created through `db::init_pool` on the `DATABASE_URL` the repository's CI sets, then asserts three things: a `GET /` with `Accept-Encoding: gzip` answers with `content-encoding: gzip` and a body that inflates to the HTML the handler renders; the same request with `br` answers `content-encoding: br`; and a request with no `Accept-Encoding` carries no `content-encoding` header and the plain body. A fourth case fetches `/static/css/style.css` with `gzip` to cover the `Files` service. It then runs what `.github/workflows/ci.yml` runs for this crate: `sqlx database create` and `sqlx migrate run --source=./basics/todo/migrations`, `cargo check`, `cargo test -p todo`, and `cargo clippy` and `cargo +nightly fmt --check` from the `justfile`.

The pull request links back to the Linear issue and lists the middleware line, the test module and the measured sizes of `/` and the three stylesheets with and without `gzip`, read from the test responses in the sandbox, so the reviewer sees what the change saves rather than an estimate.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "codex",
  "input": "A Linear issue labelled agent says: \"Enable response compression on the todo app so HTML and CSS are sent gzip or brotli when the browser accepts it.\" Read Cargo.toml, the workspace Cargo.toml and Cargo.lock, src/main.rs, src/api.rs, templates/index.html.tera, the static directory, the justfile and .github/workflows/ci.yml first. Add actix_web::middleware::Compress::default() to the App so handler responses, the static files service and the error pages are compressed according to Accept-Encoding; confirm the brotli, flate2 and zstd crates are already in Cargo.lock and add no dependency. Add a test module using actix_web::test that builds the App with a temporary SQLite pool from DATABASE_URL and checks GET / with gzip and with br returns the matching content-encoding and a body that decodes to the rendered HTML, that a request without Accept-Encoding has no content-encoding header, and that /static/css/style.css is compressed too. Run sqlx database create and sqlx migrate run as the CI workflow does, cargo check, cargo test for this crate, cargo clippy and cargo fmt --check, record the compressed and uncompressed sizes of / and each stylesheet from the test responses, and paste the outputs in the pull request. Open a pull request that links the issue. Do not change routes, templates, the session setup or any migration.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request with one middleware line in `src/main.rs`, a `#[cfg(test)]` module beside it, and no change to `Cargo.toml` or `Cargo.lock`. The description shows the `cargo test -p todo` output with the four new cases, the clippy and fmt results, and a small table of byte sizes for `/` and the three stylesheets as served plain and as served with `gzip`, taken from the responses the tests received in the sandbox.

The repository's `CI` workflow runs on the pull request, creates the SQLite database, runs the migrations and executes `cargo test --workspace`, so the new cases run in CI alongside every other example. A reviewer checks that `Compress` wraps the `Files` service and the error handlers as well as the handlers, that no request without `Accept-Encoding` changed, and that the session cookie set by `actix-session` still arrives on compressed responses. Then they merge; no configuration or deployment change is needed because negotiation happens per request.

## Run it on every Linear issue labelled agent

In the console, an automation with a `linear` trigger on `linear.issue.labeled` and the label `agent` starts one run per labelled issue, with the issue as its context, in the Project's repository. Changes made by an app integration never fire it, so the agent's own comment on the issue does not start another run.

From your own server, the same run is one `POST /o/{org}/sessions` per issue: put the repository in `resources`, and add the issue's `https://linear.app/<workspace>/issue/<ID>` URL there too so Rush reads it through your Linear connection into the prompt. The key's `webhook_url` posts `run.completed` or `run.failed` when the turn finishes, with the `session_url` to read the pull request link.

## Why run it on Rush?

Compression is a one-line change whose failure modes are all at runtime: a middleware added inside the wrong scope that misses the static files, a client that sends `Accept-Encoding: identity` and gets a compressed body anyway, or a test suite that never asks for an encoding and so never notices. In a Rush sandbox the agent builds and runs the real app against a real SQLite database, sends requests with and without each encoding, and keeps the responses in the transcript, so the pull request shows the headers and the byte counts a browser would see.

Starting from a Linear label turns a small performance issue into a reviewed pull request without anyone checking out the repository. A team with several Actix services labels one issue per service, and each run reads that service's own `App` builder and puts the middleware where it belongs.

## Frequently asked questions

### Does this add a dependency?

No. `actix-web` 4 enables its `compress-brotli`, `compress-gzip` and `compress-zstd` features by default, and the workspace `Cargo.lock` already resolves `brotli`, `flate2` and `zstd`. The agent checks the lock file before it writes anything and says so in the pull request; a project that had turned those features off would get a one-line `features` change instead.

### Does it compress the static CSS as well as the HTML?

Yes, as long as the middleware wraps the `Files` service, which is why the agent places it on the `App` rather than on one scope. One of the new tests fetches `/static/css/style.css` with `Accept-Encoding: gzip` and asserts the `content-encoding` header, so a later refactor that moves the service outside the middleware fails the test.

### What happens for a client that does not accept compression?

`Compress::default()` negotiates per request from `Accept-Encoding`. A request without the header, or with `identity`, receives the plain body and no `content-encoding`, which one of the tests checks. Nothing about the handlers or the templates changes.

### Will the session cookie still work?

Yes. `actix-session` sets the cookie on the response headers, and compression touches only the body. The agent's test for `GET /` reads the inflated body and the headers from the same response, so a change that dropped headers would show up there.

## More Actix Web jobs

- [Add CORS to an Actix Web API](https://getrush.ai/run/add-cors/actix/)
- [Add CSRF Protection to an Actix Web App](https://getrush.ai/run/add-csrf-protection/actix/)
- [Add Cursor Pagination to an Actix Web API](https://getrush.ai/run/add-cursor-pagination/actix/)

## The same job on other stacks

- [Add Response Compression to an Axum API](https://getrush.ai/run/add-compression/axum/)
- [Add Response Compression to an Echo App](https://getrush.ai/run/add-compression/echo/)
- [Add Response Compression to a Fastify App](https://getrush.ai/run/add-compression/fastify/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
