public class HelloWorld implements HttpFunction {
@Override
public void service(HttpRequest request, HttpResponse response)
throws Exception {
System.out.println("Hello World! Path: " + request.getPath());
}
}
2. Run function:
```bash
./gradlew runFunction -Prun.functionTarget=com.example.HelloWorld
Curl to /favicon.ico:
curl localhost:8080/favicon.ico
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.
For production environment, there exist some workaround but it needs to be very precisely executed, otherwise some odd errors (502 codes) will occur. I can give more detail if someone is interested.
Expected behaviour
According to Functions framework documentation, requests to
/favicon.ico
and/robots.txt
should return a 404 status without calling the 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
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()); } }
/favicon.ico
:/favicon.ico
:Possible fix
I believe that the bug is at the
NotFoundHandler
class, that executes thesuper
after writing the 404 error. I am not familiar with Jetty's handlers API, but we may see that other jetty handlers (InetAccessHandler.java) doreturn
right after generating thesendError
.PR for this: https://github.com/GoogleCloudPlatform/functions-framework-java/pull/226
Related