Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Migrates all downstream client/server functions from the deprecated
fastly_http_reqWASM module to the newfastly_http_downstreammodule, and adds thetlsClientServernameproperty which exposes the Server hostname from the TLS handshake, aligning the JS SDK with Fastly's recommended approach and enabling access to additional APIs that were previously unavailable.New Property
tlsClientServername- Returns the SNI hostname from the TLS handshake (e.g.,"example.com")Migrated Functions (10 total)
All downstream functions now use
fastly_http_downstreamwith request handle parameter:downstream_client_ip_addrdownstream_server_ip_addrdownstream_tls_cipher_openssl_namedownstream_tls_protocoldownstream_tls_client_hellodownstream_tls_raw_client_certificatedownstream_tls_ja3_md5downstream_tls_ja4downstream_client_h2_fingerprintdownstream_client_oh_fingerprintInvestigation
The JS SDK was using the
fastly_http_reqmodule for downstream functions, but these functions existed in two places in the Fastly host API:fastly_http_req(legacy) - Functions don't require a request handle parameterfastly_http_downstream(modern) - Functions require a request handle as the first parameterTo understand the correct function signatures for
fastly_http_downstream, I had a look at the Rust SDK's implementation infastly-sys:This confirmed that:
fastly_http_downstreamfunctions requirereq_handle: RequestHandleas the first parameterdownstream_tls_client_servernamefunction is available in this module (but not infastly_http_req)The JS SDK's existing code was using
fastly_http_reqwithout the request handle, which worked but didn't provide access to newer APIs likedownstream_tls_client_servername.Implementation
The key architectural change is that
fastly_http_downstreamfunctions require a request handle as the first parameter, whereas the oldfastly_http_reqfunctions were static:1. WASM Host Import (
runtime/fastly/host-api/fastly.h)Changed module from
fastly_http_reqtofastly_http_downstreamand addedreq_handleparameter to all functions:2. C++ Host API Wrapper (
runtime/fastly/host-api/host_api_fastly.h+host_api.cpp)Converted static methods to instance methods that use
this->handle:3. JavaScript Bindings (
runtime/fastly/builtins/fetch-event.h+fetch-event.cpp)RequestHandleslot toClientInfoandServerInfoto store the request handleServernameslot for caching the SNI valueget_request_handle()to retrieve handle from slotreq.downstream_tls_ja4()instead ofHttpReq::http_req_downstream_tls_ja4()tls_client_servername_getgetter and registeredtlsClientServernamepropertyFiles Changed
runtime/fastly/host-api/fastly.hfastly_http_downstream, addedreq_handleparam, addeddownstream_tls_client_servernameruntime/fastly/host-api/host_api_fastly.hdownstream_tls_client_servername()runtime/fastly/host-api/host_api.cppthis->handle, addeddownstream_tls_client_servername()runtime/fastly/builtins/fetch-event.hRequestHandleslot to ClientInfo/ServerInfo, addedServernameslot, added getter declarationruntime/fastly/builtins/fetch-event.cppget_request_handle()helper, updated all getters, addedtlsClientServernamepropertytypes/globals.d.tstlsClientServernamedocumentation/docs/globals/FetchEvent/FetchEvent.mdxtlsClientServernameintegration-tests/js-compute/fixtures/app/src/client.jstlsClientServernameintegration-tests/js-compute/fixtures/app/tests.jsontlsClientServernameTesting
Local Build
Built the js-compute-runtime from source:
cd js-compute-runtime npm run build:releaseLocal Testing (Viceroy)
Local testing with Viceroy 0.16.1 fails because Viceroy doesn't yet support the
fastly_http_downstreammodule:This is expected - Viceroy needs an update to support the new module.
Edge Deployment
Created a test Compute service and deployed to Fastly edge:
cd js-test-mcsoc-3081 npm install npm run build fastly compute publishTest endpoint: https://specially-usable-eft.edgecompute.app/
Sample response:
{ "clientIP": "161.51.218.71", "tlsJA3MD5": "375C6162A492DFBF2795909110CE8424", "tlsJA4": "t13d4907h2_0d8feac7bc37_7395dae3b2f3", "h2Fingerprint": "2:0;3:100;4:10485760|1048510465|1:0:0:16|m,s,a,p", "ohFingerprint": "aB:a6:aT", "tlsProtocol": "TLSv1.3", "tlsCipher": "TLS_CHACHA20_POLY1305_SHA256", "tlsClientServername": "specially-usable-eft.edgecompute.app" }All existing properties continue to work correctly, and the new
tlsClientServernamereturns the expected SNI hostname.Breaking Changes
None - this is a transparent migration. The JavaScript API remains unchanged for existing properties.
TODO
fastly_http_downstreammodule for local testingChecklist
tlsClientServernameproperty working