Skip to content

curl does not automatically resolve *.localhost like Chrome does. #9192

@TheKnarf

Description

@TheKnarf

I did this

In my local development env I got Hasura running and responding on hasura.localhost. This works fine in Chrome, I can open the web UI and do stuff from there. However when querying it get the following error

$ curl -g \
-X POST \
-H "Content-Type: application/json" \
-d '{"query":"query MyQuery { user { id email } }"}' \
http://hasura.localhost/v1/graphql

curl: (6) Could not resolve host: hasura.localhost

This seems to break RFC-6761:

Name resolution APIs and libraries SHOULD recognize localhost names as special and SHOULD always return the IP loopback address for address queries and negative responses for all other query types. Name resolution APIs SHOULD NOT send queries for localhost names to their configured caching DNS server(s).

So it seems that Chrome resolves hasura.localhost as the localhost loopback, while curl does not.

Now there is a simple fix for my use case, I can simply add --resolve hasura.localhost:80:127.0.0.1 to my curl command and it works fine. However this should not be necessary according to RFC-6761.

I expected the following

To get an result from the endpoint without having to add --resolve.

curl/libcurl version

curl -V
curl 7.79.1 (x86_64-apple-darwin21.0) libcurl/7.79.1 (SecureTransport) LibreSSL/3.3.6 zlib/1.2.11 nghttp2/1.45.1
Release-Date: 2021-09-22
Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS GSS-API HSTS HTTP2 HTTPS-proxy IPv6 Kerberos Largefile libz MultiSSL NTLM NTLM_WB SPNEGO SSL UnixSockets

operating system

uname -a
Darwin Mbp13arm.local 21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:29 PDT 2022; root:xnu-8020.121.3~4/RELEASE_ARM64_T8101 arm64

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions