Visitar URL original
bpo-34711: Return HTTPStatus.NOT_FOUND if path.endswith(/) and not a directory by aixtools · Pull Request #9687 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20260217003309/https://github.com/python/cpython/pull/9687
Skip to content
/ cpython Public

bpo-34711: Return HTTPStatus.NOT_FOUND if path.endswith(/) and not a directory#9687

Merged
ncoghlan merged 2 commits intopython:masterfrom
aixtools:bpo-34711
Dec 26, 2018
Merged

bpo-34711: Return HTTPStatus.NOT_FOUND if path.endswith(/) and not a directory#9687
ncoghlan merged 2 commits intopython:masterfrom
aixtools:bpo-34711

Conversation

@aixtools
Copy link
Contributor

@aixtools aixtools commented Oct 3, 2018 •

Please provide guidelines on how much, if any comments, to have in Lib/http/server.py.

I assume there is too much now, while my gut says no comments may only make people wonder why this is being done.

https://bugs.python.org/issue34711

@asvetlov
Copy link
Contributor

asvetlov commented Oct 3, 2018

Would you add a unit test?

@aixtools
Copy link
Contributor Author

aixtools commented Oct 3, 2018

I do not understand the question. This PR is to allow an existing test to pass in unique situations - rather than code exceptions in the test.

Issue17324: -- see https://bugs.python.org/issue17324#msg183247 says, literally:

  1. Note that the server has served the contents of "foo.txt" as "foo.txt/". It shouldn't do that!

My current understanding is that the goal is to bring the existing "unit test" test_httpservers and Lib/http/server.py into sync with the quote above.

It is know "known" that Windows, under certain conditions, and AIX (always) will return a filename ending in "/" as "OK" rather than as "NOT_FOUND".

However, if you could explain what you feel is missing perhaps this could be expanded with another unit test.

@asvetlov
Copy link
Contributor

asvetlov commented Oct 3, 2018

You are adding a new code to fix a bug.
A test for checking the behavior to never fall into the problem again as a result of some http server refactoring is very desirable.

@aixtools
Copy link
Contributor Author

aixtools commented Oct 4, 2018

You are adding a new code to fix a bug.
A test for checking the behavior to never fall into the problem again as a result of some http server refactoring is very desirable.

Well, since you can think of it, I guess you are much smarter than I. I can not figure out how to test this in a way it is not already being tested.

In the test I am "adding this code for" it tests:

    def test_get(self):
        #constructs the path relative to the root directory of the HTTPServer
        response = self.request(self.base_url + '/test')
        self.check_status_and_reason(response, HTTPStatus.OK, data=self.data)
        # check for trailing "/" which should return 404. See Issue17324
        response = self.request(self.base_url + '/test/')
        self.check_status_and_reason(response, HTTPStatus.NOT_FOUND)
        response = self.request(self.base_url + '/')
        self.check_status_and_reason(response, HTTPStatus.OK)
        response = self.request(self.base_url)
        self.check_status_and_reason(response, HTTPStatus.MOVED_PERMANENTLY)
        response = self.request(self.base_url + '/?hi=2')
        self.check_status_and_reason(response, HTTPStatus.OK)
        response = self.request(self.base_url + '?hi=1')
        self.check_status_and_reason(response, HTTPStatus.MOVED_PERMANENTLY)
        self.assertEqual(response.getheader("Location"),
                         self.base_url + "/?hi=1")
        response = self.request('/ThisDoesNotExist')
        self.check_status_and_reason(response, HTTPStatus.NOT_FOUND)
        response = self.request('/' + 'ThisDoesNotExist' + '/')
        self.check_status_and_reason(response, HTTPStatus.NOT_FOUND)

and

    def test_path_without_leading_slash(self):
        response = self.request(self.tempdir_name + '/test')
        self.check_status_and_reason(response, HTTPStatus.OK, data=self.data)
        response = self.request(self.tempdir_name + '/test/')
        self.check_status_and_reason(response, HTTPStatus.NOT_FOUND)
        response = self.request(self.tempdir_name + '/')
        self.check_status_and_reason(response, HTTPStatus.OK)
        response = self.request(self.tempdir_name)
        self.check_status_and_reason(response, HTTPStatus.MOVED_PERMANENTLY)
        response = self.request(self.tempdir_name + '/?hi=2')
        self.check_status_and_reason(response, HTTPStatus.OK)
        response = self.request(self.tempdir_name + '?hi=1')
        self.check_status_and_reason(response, HTTPStatus.MOVED_PERMANENTLY)
        self.assertEqual(response.getheader("Location"),
                         self.tempdir_name + "/?hi=1")

Please help me out with howto test this addition - that is not already tested above?

@aixtools
Copy link
Contributor Author

aixtools commented Oct 5, 2018 via email

@taleinat
Copy link
Contributor

Which test(s) currently fail(s) on AIX? Can you perhaps supply a link to such failures on a buildbot?

Is there a test case for the similar issue with junctions on Windows? I assume not since this would be failing on our Windows CI builds. If this fixes that too, it could be good to add such a test.

@aixtools
Copy link
Contributor Author

aixtools commented Oct 29, 2018 via email

Copy link
Contributor

@ncoghlan ncoghlan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just waiting for the new CI run that was triggered by my rewording of the NEWS entry.

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

Successfully merging this pull request may close these issues.

6 participants