Skip to content

bug: Not detecting redirects in HTTP versions >HTTP/1.1 #41

@xnumad

Description

@xnumad

Consequence by example

https://www.freifunk-karte.de/debug.php:

https://mesh.freifunknord.de/data/nodes.json returns no result

(which is false, as you can see when opening the URL yourself)
As an eventual result, none of the nodes defined therein are in the map.

Core issue

Failing to parse lower case headers in HTTP versions >HTTP/1.1
A request to the URL from the example, https://mesh.freifunknord.de/data/nodes.json, has the response header location: https://map.freifunknord.de/data/nodes.json
("Freifunk Nord" is only an example Freifunk community affected by this, using HTTP/2, there are probably many other that are as well using HTTP versions newer than HTTP/1.1 on their web servers.)

This expression however is case-sensitive and expects capitalization:

preg_match("/(Location:|URI:)[^(\n)]*/", $header, $matches);

Workaround

Force use of HTTP/1.1
use curl --http1.1 (actually, its equivalent option value for libcurl: CURLOPT_HTTP_VERSION=CURL_HTTP_VERSION_1_1)
(Assuming the new web servers still support it, which is highly probable though.)
(Although this might actually in turn break support for (Freifunk community) web servers not supporting HTTP/1.1, e.g. some only supporting HTTP/1.0. If there even are any such old servers used (by Freifunk communities).)

Quickest fix

Make the redirect parser work on the lowercase headers, simply by making it case-insensitive.
For this, add an i after the closing / of the regular expression.

-                preg_match("/(Location:|URI:)[^(\n)]*/", $header, $matches);
+                preg_match("/(Location:|URI:)[^(\n)]*/i", $header, $matches);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions