Skip to content

fetch: GET sends "null" body #660

@undernorthernsky

Description

@undernorthernsky

Build from current master, 'make test' reports no errors.

> await fetch('http://localhost:9999')

// second shell
$ nc -l -p 9999
GET / HTTP/1.1
Host: localhost:9999
User-Agent: txiki.js/24.6.0
Accept: */*
Content-Length: 4
Content-Type: application/x-www-form-urlencoded

null

Some servers don't like this (e.g. google.com) and respond with 400.

> await fetch('http://localhost:9999', {method: 'GET'})

// as above, same as {method: 'GET', body: null}

> await fetch('http://localhost:9999', {method: 'HEAD'})

HEAD / HTTP/1.1
Host: localhost:9999
User-Agent: txiki.js/24.6.0
Accept: */*

> await fetch('http://localhost:9999', {method: 'GET', body: ''})

GET / HTTP/1.1
Host: localhost:9999
User-Agent: txiki.js/24.6.0
Accept: */*
content-type: text/plain;charset=UTF-8
Content-Length: 0

not sure where exactly it goes wrong; note: 'content-type' vs 'Content-Type'. maybe the latter is the curl default.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions