Can Requests for `favicon.ico` be Blocked when Using `$.interface.http` Sources?

This topic was automatically generated from Slack. You can find the original thread here.

: Is it possible to block requests for favicon.ico when using $.interface.http sources?

Yes, it is possible to block requests for favicon.ico when using $.interface.http sources. You can do this by checking the request path in your code and returning a response immediately if the path is /favicon.ico. Here’s an example of how you can do this: export default defineComponent({ async run({ $ }) { if ($.interface.http.req.path === '/favicon.ico') { $.interface.http.respond({ status: 200, body: '', }); return; } // Your normal code here }, }); In this example, when a request is made to favicon.ico, the code immediately responds with a 200 status and an empty body, effectively blocking the request. The return statement ensures that the rest of your code doesn’t run for these requests.

:point_up_2:

Ah, cool!

So we can put a bunch of different conditional logic in there as well! :ok_hand:

this isn’t exposed on the $.interface.http.req.path event (we need to improve Pi’s sources on event sources). @U05A7KLNALC if I’m developing an event source, I have access to the data in the HTTP request the event arg passed to run:

async run(event) { ...

The $ is not exposed in sources and the HTTP interface is accessed as a prop on this. Please consult the docs on the component API and try again.

but if you console.log the event var in your source, you should see the request details there

I apologize for the confusion earlier. You’re correct. In the context of a Pipedream source component, the HTTP interface is accessed differently compared to a workflow. Here’s how you can block requests for favicon.ico in a source component: export default { name: "http-source-example", version: "0.0.1", props: { http: "$.interface.http", }, async run(event) { const path = this.http.path if (path === "/favicon.ico") { this.http.respond({ status: 200, body: '', }); } else { // Your normal code here } }, }; In this example, when a request is made to favicon.ico, the code immediately responds with a 200 status and an empty body, effectively blocking the request. The rest of your code doesn’t run for these requests.

Yeah np, we figured it out! :+1:

Pi’s advice was enough to get us started. :slightly_smiling_face:

haha good thanks. Yeah it’s so close on some questions and then the hallucinations win