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

XMLHttpRequest may not work with 'HEAD' method #1273

Open
Armored-Dragon opened this issue Dec 17, 2024 · 0 comments
Open

XMLHttpRequest may not work with 'HEAD' method #1273

Armored-Dragon opened this issue Dec 17, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Armored-Dragon
Copy link
Member

Armored-Dragon commented Dec 17, 2024

When creating a new XMLHttpRequest using our implementation, setting the method as "HEAD" will never let the request actually complete. The request seems to be perpetually in a "OPENED" state. I did a quick look at what I believe to be the relevant code and I did not see anything immediately jump out at me as an obvious blocker, though I didn't actually poke at anything.

Here is the code I used to attempt to use 'HEAD'

function fetch(url, options = {method: "GET"}) {
    return new Promise((resolve, reject) => {
        let req = new XMLHttpRequest();

        req.onreadystatechange = function () {
            console.log(req.readyState);        // Always "1"
            console.log(req.status);            // Always "0"

            if (req.readyState === req.DONE) {  // Never true
                if (req.status === 200) {
                    console.log("Success");
                    console.log("Content type:", req.getResponseHeader("content-type"));
                    resolve(req.response);
        
                } else {
                    console.log("Error", req.status, req.statusText);
                    reject();
                }
            }
        };

        req.open(options.method, url);
        req.send();
    });
}

Call this function with

fetch(URL, {method: METHOD})

Example:

fetch('https://adragon.dev/img/logos/armoreddragonpfp.png', {method: 'HEAD')

The above code works when I set the method to a "GET" request and preforms as expected.
I have also double checked that the resource I want to retrieve is accessible using https://httpfy.io/http-request-tester-online-tools/.

@daleglass daleglass added the bug Something isn't working label Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants