Skip to content

Requesting /favicon.ico or /robots.txt invokes function, although it shouldn't according to doc #225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alsoba13 opened this issue Aug 16, 2023 · 1 comment · Fixed by #226
Assignees
Labels
bug Something isn't working P2

Comments

@alsoba13
Copy link
Contributor

alsoba13 commented Aug 16, 2023

Expected behaviour

According to Functions framework documentation, requests to /favicon.ico and /robots.txt should return a 404 status without calling the function:

Note that the framework must listen to all inbound paths (.*) and route these requests to the function, with the following exceptions:

  • /robots.txt - must respond with 404 without invoking function
  • /favicon.ico - must response with 404 without invoking function

Actual behaviour

When requesting a /favicon.ico or /robots.txt, a 404 status is returned, but the function is actually invoked, with all its possible side effects.

Reproduction

  1. Take the Hello World example from this repository, but write directly to stdout:
package com.example;

import com.google.cloud.functions.HttpFunction;
import com.google.cloud.functions.HttpRequest;
import com.google.cloud.functions.HttpResponse;

public class HelloWorld implements HttpFunction {
  @Override
  public void service(HttpRequest request, HttpResponse response)
      throws Exception {
    System.out.println("Hello World! Path: " + request.getPath());
  }
}
  1. Run function:
./gradlew runFunction -Prun.functionTarget=com.example.HelloWorld
  1. Curl to /favicon.ico:
curl localhost:8080/favicon.ico
  1. See the result in the console to check that the function is executed with /favicon.ico:
Hello World! Path: /favicon.ico

Possible fix

I believe that the bug is at the NotFoundHandler class, that executes the super after writing the 404 error. I am not familiar with Jetty's handlers API, but we may see that other jetty handlers (InetAccessHandler.java) do return right after generating the sendError.

PR for this: #226

Related

@HKWinterhalter
Copy link
Contributor

Thanks for finding and reporting on this! I have approved PR #226

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P2
Projects
None yet
3 participants