On 14/01/2026 04:10, Gianluca Cannata wrote:
Hello Samuel and the Hurd team,

this is the second patch in the series of patches that tries to fix
the httpfs translator.

This patch fixes the open_connection function by removing the HEAD
request and using only a GET request to parse the headers and the body
of the HTTP response.

Sincerely

Gianluca


FYI, think a bit more 'extreme' levels of "minimal change" per patch submission. It helps Samuel review things and apply them faster the simpler each patch is.


Per my earlier reply, I do advise keeping the HEAD initial request. However add the Host, User-Agent, and a "Connection: close" header to the message sent.
 --> that addition by itself would be one patch.


Then, HTTP/1.1 specification currently requires support for at least 8KB URLs. --> that is a patch changing the 'buffer' variable to be large enough for that plus the other message bytes would be good.


The old code took the HEAD reply and searched for exactly "200" status response. That was good, however all status codes 200-299 (except 204) are valid and equivalent to 200 status. --> that is another patch accepting all the other 2xx responses to move on to the GET stage. Maybe a matching alteration to the GET status handler to keep things working in sync.


At this point in the refactor, it would be nice to re-use the TCP connection the HEAD request used for the followup GET request. --> that is another patch changing the socket FD used by the GET request and switching the HEAD to send "Connection: keep-alive".



+       /* HTTP/1.1 request correctly formatted */
+    /* We use \r\n as per requested by RFC standard */
+    int req_len = snprintf(buffer, sizeof(buffer),
+             "GET %s HTTP/1.1\r\n"
+             "Host: %s\r\n"
+             "User-Agent: GNU-Hurd-httpfs/0.1\r\n"
+             "Connection: close\r\n\r\n",
+             relative_path, dir_tok);


Best to keep the version advertised as 1.0 for now.

FYI, you can still use most 1.1 features, but actually sending "HTTP/1.1" in the request tells the server it is allowed to use some complex mechanisms that this translator simply cannot handle right now.



+    /* Verify if the response is valid */
+ if (!strstr(buffer, " 200") && !strstr(buffer, " 301") && !strstr(buffer, " 302")) { + fprintf(stderr, "httpfs: Server returned error or not found for %s\n", relative_path);
+        close(*fd);
+        return ENOENT;
+    }

The 3xx codes are not yet handled correctly. Best not to accept them yet.


Best revert to the status code parse that old code was doing. All 100-399 status codes are valid, with a few special cases that will need to be checked and handled by the time this translator is fully updated. Doing that with numeric comparisons is clearer code, and far more efficient than many string comparisons.



PS. If you want any assistance or advice about the protocol side of this work please feel free to drop me an email. I am one of the IETF HTTP WG members.

HTH
Amos


Reply via email to