PHPackages                             weijiajia/saloonphp-header-synchronize-plugin - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. weijiajia/saloonphp-header-synchronize-plugin

ActiveLibrary

weijiajia/saloonphp-header-synchronize-plugin
=============================================

A Saloon PHP plugin for synchronizing headers between requests to maintain session state and authentication

027PHP

Since May 21Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/jackchang1025/saloonphp-header-synchronize-plugin)[ Packagist](https://packagist.org/packages/weijiajia/saloonphp-header-synchronize-plugin)[ RSS](/packages/weijiajia-saloonphp-header-synchronize-plugin/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Saloon PHP Header Synchronize Plugin
====================================

[](#saloon-php-header-synchronize-plugin)

[中文文档](README.zh.md) | English

[![Latest Version on Packagist](https://camo.githubusercontent.com/40013269cf8e073242745f27c75ee4067a9fd514cbb604e0ed074e4db4f8279a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7765696a69616a69612f73616c6f6f6e7068702d6865616465722d73796e6368726f6e697a652d706c7567696e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/weijiajia/saloonphp-header-synchronize-plugin)[![Total Downloads](https://camo.githubusercontent.com/68de241dae0f2d1f211972736ac27f579ea62e941d3ffd3545492785670896f8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7765696a69616a69612f73616c6f6f6e7068702d6865616465722d73796e6368726f6e697a652d706c7567696e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/weijiajia/saloonphp-header-synchronize-plugin)

A plugin for [Saloon PHP](https://github.com/saloonphp/saloon) that synchronizes headers between requests, useful for maintaining session state, authentication tokens, and other persistent headers across multiple API requests.

Features
--------

[](#features)

- Seamless header synchronization between requests
- Multiple storage drivers (Array, File, PSR-16 Cache)
- Easy integration with Saloon HTTP clients
- Configurable header sync for specific HTTP methods
- Minimal setup required

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require weijiajia/saloonphp-header-synchronize-plugin
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

1. Implement the `HeaderSynchronize` interface on your connector or request class:

```
use Saloon\Http\Connector;
use Weijiajia\SaloonphpHeaderSynchronizePlugin\Contracts\HeaderSynchronize;
use Weijiajia\SaloonphpHeaderSynchronizePlugin\HasHeaderSynchronize;
use Saloon\Repositories\ArrayStore;
use Weijiajia\SaloonphpHeaderSynchronizePlugin\Contracts\HeaderSynchronizeDriver;

class ApiConnector extends Connector implements HeaderSynchronize
{
    use HasHeaderSynchronize;

    // Define headers you want to synchronize between requests
    protected function defaultHeaderSynchronizes(): array
    {
        return [
            'Authorization',
            'Session-Token',
            // Other headers you want to persist
        ];
    }

    // Optionally specify which HTTP methods should use header synchronization
    protected function getHeaderSynchronizeMethods(): array
    {
        return [
            Method::GET,
            Method::POST,
            // Other methods
        ];
    }
}
```

### Storage Drivers

[](#storage-drivers)

#### Array Storage (Default)

[](#array-storage-default)

The default driver uses in-memory array storage for the duration of the PHP execution:

```
// Already used by default, but you can explicitly define it:
$connector = new ApiConnector();
$connector->withHeaderSynchronizeDriver(new ArrayStoreHeaderSynchronize());
```

#### File Storage

[](#file-storage)

For persisting headers between requests across different script executions:

```
use Weijiajia\SaloonphpHeaderSynchronizePlugin\Driver\FileHeaderSynchronize;

$connector = new ApiConnector();
$connector->withHeaderSynchronizeDriver(
    new FileHeaderSynchronize('/path/to/headers.json')
);
```

#### PSR-16 Cache Storage

[](#psr-16-cache-storage)

Use any PSR-16 compatible cache library:

```
use Weijiajia\SaloonphpHeaderSynchronizePlugin\Driver\CacheHeaderSynchronize;

$connector = new ApiConnector();
$connector->withHeaderSynchronizeDriver(
    new CacheHeaderSynchronize(
        $cacheImplementation, // Any PSR-16 CacheInterface implementation
        'api_headers',        // Cache key
        [],                   // Default data
        3600                  // TTL in seconds
    )
);
```

### Usage Example

[](#usage-example)

```
$connector = new ApiConnector();

// First request (e.g., login)
$response = $connector->send(new LoginRequest($credentials));
// Headers like 'Authorization' are automatically captured

// Subsequent requests will include synchronized headers automatically
$profileResponse = $connector->send(new GetProfileRequest());
// The 'Authorization' header was automatically included
```

Creating Custom Drivers
-----------------------

[](#creating-custom-drivers)

You can create custom header synchronization drivers by implementing the `HeaderSynchronizeDriver` interface:

```
use Weijiajia\SaloonphpHeaderSynchronizePlugin\Contracts\HeaderSynchronizeDriver;
use Saloon\Http\Response;
use Saloon\Http\PendingRequest;
use Saloon\Repositories\ArrayStore;

class CustomHeaderSynchronize implements HeaderSynchronizeDriver
{
    public function extractHeader(Response $response): Response
    {
        // Logic to extract and store headers from responses
        return $response;
    }

    public function withHeader(PendingRequest $pendingRequest, ArrayStore $persistentHeaders): PendingRequest
    {
        // Logic to add stored headers to pending requests
        return $pendingRequest;
    }
}
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity14

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/636557533fde1107bb301eca908de1c17c9ea7073d5c9c0fbad725ccd0800bde?d=identicon)[jackchang1025](/maintainers/jackchang1025)

---

Top Contributors

[![422066139](https://avatars.githubusercontent.com/u/1780162?v=4)](https://github.com/422066139 "422066139 (2 commits)")

### Embed Badge

![Health badge](/badges/weijiajia-saloonphp-header-synchronize-plugin/health.svg)

```
[![Health](https://phpackages.com/badges/weijiajia-saloonphp-header-synchronize-plugin/health.svg)](https://phpackages.com/packages/weijiajia-saloonphp-header-synchronize-plugin)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
