Skip to content
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

Add user agent to simple-get #1883

Closed
wants to merge 1 commit into from
Closed

Add user agent to simple-get #1883

wants to merge 1 commit into from

Conversation

hackermare
Copy link

Some sites (including Discord now) return a 403 error if no user agent is specified. Adding a user agent to the simple-get fixes the problem.

Some sites (including Discord now) return a 403 error if no user agent is specified. Adding a user agent to the simple-get fixes the problem.
@almeidx
Copy link

almeidx commented Aug 23, 2021

From the Discord Developers server:

At around 3:00 PDT, we became aware of an issue impacting bots' ability to gather images and other attachments from our CDN without specifying a User-Agent header. Impacted bots were experiencing 403 errors when attempting to gather files from our CDN without a User-Agent header. This change was not intentional, and has been resolved.

@hackermare
Copy link
Author

Would it still be a good idea to add a user agent?

@zbjornson
Copy link
Collaborator

In another Node.js package I help maintain, we decided to not set a default user-agent because Node.js doesn't set a default either. We did expose the ability for users to set any HTTP option (including any header) though. I'm not sure how we would provide that functionality in node-canvas without significantly deviating from the HTML spec, so I'm open to adding a U-A header (but something more accurate like node-canvas/<node-canvas-ver> node/<node-ver>).

@LinusU @chearon ?

@chearon
Copy link
Collaborator

chearon commented Aug 24, 2021

I'm not sure how we would provide that functionality in node-canvas without significantly deviating from the HTML spec

Providing a hook wouldn't be bad would it? Something like Canvas.on("request", config => config.headers.... That would be my first pick, followed by a hard-coded node-canvas/<ver> header.

@jimmywarting
Copy link
Contributor

I personally would like to see simple-get removed. along with Image ( #1845 )
simple-get isn't exposed in any meaningful way that it can be used somehow so, why not keep it that way?

a better proper way to load a image is via: createImageBitmap

nodejs have added support for blobs, so one way to load binary images could be to do:

import { Blob } from 'node:buffer'
import { createImageBitmap }  from 'canvas/createImageBitmap.js'

const bitmap = await createImageBitmap(new Blob([ uint8 ]))
// Later paint bitmap to canvas

@zbjornson
Copy link
Collaborator

simple-get isn't exposed in any meaningful way that it can be used somehow

I'm sure you saw this already, but it's used when img.src = "a URL". createImageBitmap doesn't currently accept a URL, and based on the number of issues opened here, quite a few people use img.src=url. More interesting info on the topic here: https://wiki.whatwg.org/wiki/ImageBitmap_Constructor_taking_URL

@jimmywarting
Copy link
Contributor

jimmywarting commented Sep 1, 2021

well, i know it's being used when img.src is set but you have no direct access to simple-get

besides, not everything can be loaded with a simple get request. Other things require cookies or some other headers or methods.

@hackermare hackermare closed this Oct 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants