Skip to content

Conversation

@TartanLlama
Copy link
Contributor

@TartanLlama TartanLlama commented Dec 2, 2025

Adds support for shielding. Example:

/// <reference types="@fastly/js-compute" />
    
import { Shield } from "fastly:shielding";

async function app(event) {
    const shield = new Shield('wsi-australia-au');
    // If running on the shield POP, fetch from the origin directly
    if (shield.runningOn()) {
        return await fetch('https://http-me.fastly.com/anything', { backend: 'httpme' });
    }
    // Otherwise, route the request through the shield using an encrypted connection
    return await fetch(event.request, { backend: shield.encryptedBackend() });
}

addEventListener("fetch", (event) => event.respondWith(app(event)))

There is no automated test, as there's additional complexity in ensuring that the shield POP has also gone up in time for the test to run. We could potentially add one that continually sends a request to the shield until it responds, but for now I've just tested this manually, which is also what, e.g. the Go SDK does.

@TartanLlama TartanLlama changed the title Shielding support feat: Shielding support Dec 2, 2025
@TartanLlama TartanLlama requested a review from zkat December 2, 2025 15:51
if (status == 0) {
out_buf.resize(used_amount);
break;
} else if (status == FASTLY_HOST_ERROR_BUFFER_LEN) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't FASTLY_HOST_ERROR_BUFFER_LEN usually set buf_size to the expected buf_size, so you don't have to keep retrying like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually, yes, not in the case of this host call it seems. I'm following the Rust SDK behaviour fwiw

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apparently it doesn't. Absolutely rude.

@TartanLlama TartanLlama merged commit 985c55e into main Dec 10, 2025
28 of 29 checks passed
@TartanLlama TartanLlama deleted the sy/shielding branch December 10, 2025 17:54
This was referenced Dec 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants