How to stop Fastly HTTPS 308 Permanent Redirect?

638 Views Asked by At

I have a Fastly Compute@Edge service that is configured to use HTTP for the frontend domain and backend host, but when I connect I get a 308 https redirect which I'd like to stop. I'd like it to just run and return the Edge function code which doesn't seem to be executing.

My domain is www.goodapis.com and the CNAME is configured to point to nonssl.global.fastly.net. as shown by:

% dig www.goodapis.com +short
nonssl.global.fastly.net.
151.101.188.204

My backend host is pointing to example.com:80 (also without TLS), though this shouldn't matter right now since the Edge Code loaded doesn't call the backend host.

My Edge code package is the demo code from the following repo:

https://github.com/fastly/compute-starter-kit-javascript-default

with the following code (some comments removed here):

https://github.com/fastly/compute-starter-kit-javascript-default/blob/main/src/index.js

//! Default Compute@Edge template program.

/// <reference types="@fastly/js-compute" />
import welcomePage from "./[email protected]";

// The entry point for your application.
//
// Use this fetch event listener to define your main request handling logic. It could be
// used to route based on the request properties (such as method or path), send
// the request to a backend, make completely new requests, and/or generate
// synthetic responses.

addEventListener("fetch", (event) => event.respondWith(handleRequest(event)));

async function handleRequest(event) {
  // Get the client request.
  let req = event.request;

  // Filter requests that have unexpected methods.
  if (!["HEAD", "GET"].includes(req.method)) {
    return new Response("This method is not allowed", {
      status: 405,
    });
  }

  let url = new URL(req.url);

  // If request is to the `/` path...
  if (url.pathname == "/") {
    // <cut comments>
    // Send a default synthetic response.
    return new Response(welcomePage, {
      status: 200,
      headers: new Headers({ "Content-Type": "text/html; charset=utf-8" }),
    });
  }

  // Catch all other requests and return a 404.
  return new Response("The page you requested could not be found", {
    status: 404,
  });
}

However, when I call http://www.goodapis.com, I get a 308 Permanent Redirect to https://www.goodapis.com. This happens when I send a POST and after I purge the entire cache as well.

% curl http://www.goodapis.com --verbose
*   Trying 151.101.40.204:80...
* Connected to www.goodapis.com (151.101.40.204) port 80 (#0)
> GET / HTTP/1.1
> Host: www.goodapis.com
> User-Agent: curl/7.77.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 308 Permanent Redirect
< Server: Varnish
< Retry-After: 0
< Content-Length: 0
< Location: https://www.goodapis.com/
< Accept-Ranges: bytes
< Date: Mon, 23 May 2022 21:08:25 GMT
< Via: 1.1 varnish
< Connection: close
< X-Served-By: cache-sjc10043-SJC
< X-Cache: HIT
< X-Cache-Hits: 0
< 
* Closing connection 0

Anyone know why this 308 redirect happens and how it can be stopped?

2

There are 2 best solutions below

2
On BEST ANSWER

Fastly's Compute@Edge platform does not support HTTP connections. So these requests will be automatically redirected.

This is described in the Fastly documentation here: https://developer.fastly.com/learning/compute/#limitations-and-constraints

Compute@Edge services allow connections to backends on ports 80 and 443, and accept client connections on port 443 only.

If you have any further questions, then please feel free to reach out to [email protected]

Thanks.

0
On

Fastly does support http (port 80) requests and they can override the default 308 to 302 if needed. Just ask support for this.