valyala / fasthttp

Fast HTTP package for Go. Tuned for high performance. Zero memory allocations in hot paths. Up to 10x faster than net/http
MIT License
21.94k stars 1.76k forks source link

Issue: Default Path Not Set in FastHTTP Client for URIs with Only Query Parameters #1659

Open skidder opened 1 year ago

skidder commented 1 year ago

Problem Description

The FastHTTP client fails to set a default path (/) for request URIs that include only query parameters but no path. This behavior diverges from common web clients (like cURL, Chrome, Firefox) and does not align with the HTTP 1.1 specification.

Expected Behavior

An HTTP GET request for a URI like https://example.com?foo=bar should generate a request header in the format:

GET /?foo=bar

This follows the standard outlined in the HTTP 1.1 spec, section 5.3.1, which states that clients must treat an empty path as /.

Actual Behavior

Currently, FastHTTP generates a header like:

GET ?foo=bar

This can lead to failures with servers that do not default to a path of / when one is not specified.

Suggested Fix

Modify FastHTTP's RequestURI function in http.go to check for an empty path and set it to / if necessary. This ensures compatibility with a wider range of HTTP servers and adherence to the HTTP 1.1 specification.

erikdubbelboer commented 1 year ago

A pull request would be welcome! Or some code to reproduce this so we can easily write a test and fix that.