Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
xnumad opened this issue Oct 20, 2023 · 0 comments
Open

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

xnumad opened this issue Oct 20, 2023 · 0 comments

Comments

@xnumad
Copy link

xnumad commented Oct 20, 2023

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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant