Table Based redirection fastly

 have applied the configuration and cleaned what needed to be clean on Fastly configuration and the object /media/.well-known/apple-app-site-association is now returning Content-Type:txt/html which commands the browser to open the page instead of Saving As commanded by Content-Type: application/octet-stream.

 

I went for a different approach because I believe it is easier to maintain and can be useful to you in the future.

 

I have removed the following snippets:

# Snippet magentomodule_recv_mobile_app_apple_appsite_association : 70

if(req.url.path == "/.well-known/apple-app-site-association" ){

  set req.url = "/media/.well-known/apple-app-site-association";

  // return(pass);

}

# Snippet magentomodule_apple_recv : 100

if (req.url.path == "/.well-known/apple-app-site-association/") {

  error 602;

}

# Snippet magentomodule_apple_error : 100

if (obj.status == 602) {    

  set obj.status = 200;    

  set obj.http.content-type = "text/plain";    

  synthetic {""};    

  return (deliver);

}

 

I opted for a redirection based in a table so that in future, if you need other redirects, you can simply add the url to the table and avoid doing more complex configurations. With the redirect done I went to change the Content-Type header on the response.

All configuration was done on the admin backend so you can inspect and make corrections, if needed.

 

The VCL snippets go as:

#magentomodule_table_solution_redirects

#You can add more redirects to the table whenever you need.

table solution_redirects {

  "/.well-known/apple-app-site-association": "/media/.well-known/apple-app-site-association"

}

#magentomodule_solution_redirects_recv

if (table.contains(solution_redirects, req.url.path)) {

  error 618 "redirect";

}

#magentomodule_solution_redirects_error

if (obj.status == 618 && obj.response == "redirect") {

  set obj.status = 308;

  set obj.http.Location = "https://" + req.http.host + table.lookup(solution_redirects, req.url.path) + if (std.strlen(req.url.qs) > 0, "?" req.url.qs, "");

  return (deliver);

}

#magentomodule_apple_change_content_type_on_deliver

#Change header Content-Type on the fly for this object.

if (req.url ~ "/media/.well-known/apple-app-site-association") {

  set resp.http.Content-Type = "text/html";

}

 

Opening https://www.google.com/.well-known/apple-app-site-association is now returning content on the browser.

 

 

As a side note, take into account that as Content-Type: application/octet-stream is being set by Magento you should consider changing the header on the application side. This is not mandatory but would make more sense from a technical point of view.

 

Please confirm that the solution provided to you has resolved the reported issue. Support requests will be set to solved if no response is received within 3 days following this notification.


Comments