HTTP status code returned is 200 instead of 404 (programmatically, not UI-wise)
Summary
When making a request which should return a 404 (e.g., a repository that doesn't exist for a user which does exist), an HTTP status code of 200 is returned even though the UI shows a 404 page. I found this out after wasting half an hour why my link tester wasn't working when I realized it was GitLab's server.
Steps to reproduce
- Visit
https://gitlab.com/neelkamath/repo-which-does-not-existin your browser. You will see a 404 page. (This is to show that the UI works, but not programmatically). - If you're on a *nix system, run
curl -o /dev/null --silent --write-out '%{http_code}\n' https://gitlab.com/neelkamath/repo-which-does-not-exist. You'll get a 302 (I know I said 404, but that's because you get a 404 in Dart, Python, etc.). - Now let's try it in Python:
- Install Python 3
- Install dependencies:
- Windows:
pip install requests - Other:
sudo pip3 install requests
- Windows:
- Start the interactive Python console:
- Windows:
python - Other:
python3
- Windows:
- Enter this line:
import requests, and then this line:requests.get('https://gitlab.com/neelkamath/repo-which-does-not-exist').status_code. You'll get404.
- Now in Dart:
- Install Server Dart 2
- In a text editor, create a file
main.dartand enter into it:main() async { final request = await HttpClient().getUrl(Uri.parse('https://github.com/neelkamath/repo-which-does-not-exist')); final response = await request.close(); print(response.statusCode); } - Run:
dart main.dart
- Now repeat all these steps, except replace the host with something else (e.g., change
gitlabtogithub), and you'll get a 404.
What is the current bug behavior?
Incorrect HTTP status code returned for nonexistent resources.
What is the expected correct behavior?
An HTTP status code of 404 returned.
Relevant logs and/or screenshots
Output of checks
I have no idea what this section is, but yea, it's for GitLab.
Results of GitLab environment info
I'm using GitLab CE (the free account) online at GitLab.com (https://gitlab.com) and currently it's running 11.0.
Results of GitLab application Check
Nope.
Possible fixes
Nope.