annotate mercurial/strutil.py @ 20964:a939eeb94833

http: reuse authentication info after the first failed request (issue3567) [This was applied in 181108726ea5 but backed out again in af02783dea65 because of Python 2.4 issues. This edition and test-http.t works with Python 2.4.] Context: mercurial access to repository server with http access, and this server is protected by basic auth. Before patch: * mercurial try an anonymous access to server, server return 401 response and mercurial resend request with login / password information After patch: * mercurial try an anonymous access to server, server return 401 response. For all next requests, mercurial keep in memory this information (this server need basic auth information). This patch reduce the number of http access against mercurial server. Example, before patch: 10.10.168.170 - - [25/Oct/2013:15:44:51 +0200] "GET /hg/testagt?cmd=capabilities HTTP/1.1" 401 260 "-" "mercurial/proto-1.0" 10.10.168.170 - - [25/Oct/2013:15:44:52 +0200] "GET /hg/testagt?cmd=capabilities HTTP/1.1" 200 147 "-" "mercurial/proto-1.0" 10.10.168.170 - - [25/Oct/2013:15:45:00 +0200] "GET /hg/testagt?cmd=capabilities HTTP/1.1" 401 260 "-" "mercurial/proto-1.0" 10.10.168.170 - - [25/Oct/2013:15:45:01 +0200] "GET /hg/testagt?cmd=capabilities HTTP/1.1" 200 147 "-" "mercurial/proto-1.0" 10.10.168.170 - - [25/Oct/2013:15:45:03 +0200] "GET /hg/testagt?cmd=batch HTTP/1.1" 401 260 "-" "mercurial/proto-1.0" 10.10.168.170 - - [25/Oct/2013:15:45:04 +0200] "GET /hg/testagt?cmd=batch HTTP/1.1" 200 42 "-" "mercurial/proto-1.0" 10.10.168.170 - - [25/Oct/2013:15:45:06 +0200] "GET /hg/testagt?cmd=getbundle HTTP/1.1" 401 260 "-" "mercurial/proto-1.0" 10.10.168.170 - - [25/Oct/2013:15:45:07 +0200] "GET /hg/testagt?cmd=getbundle HTTP/1.1" 200 61184 "-" "mercurial/proto-1.0" 10.10.168.170 - - [25/Oct/2013:15:45:09 +0200] "GET /hg/testagt?cmd=listkeys HTTP/1.1" 401 260 "-" "mercurial/proto-1.0" 10.10.168.170 - - [25/Oct/2013:15:45:10 +0200] "GET /hg/testagt?cmd=listkeys HTTP/1.1" 200 15 "-" "mercurial/proto-1.0" 10.10.168.170 - - [25/Oct/2013:15:45:12 +0200] "GET /hg/testagt?cmd=listkeys HTTP/1.1" 401 260 "-" "mercurial/proto-1.0" 10.10.168.170 - - [25/Oct/2013:15:45:12 +0200] "GET /hg/testagt?cmd=listkeys HTTP/1.1" 200 - "-" "mercurial/proto-1.0" Example after patch: 10.10.168.170 - - [28/Oct/2013:11:49:14 +0100] "GET /hg/testagt?cmd=capabilities HTTP/1.1" 401 260 "-" "mercurial/proto-1.0" 10.10.168.170 - - [28/Oct/2013:11:49:15 +0100] "GET /hg/testagt?cmd=capabilities HTTP/1.1" 200 147 "-" "mercurial/proto-1.0" 10.10.168.170 - - [28/Oct/2013:11:49:17 +0100] "GET /hg/testagt?cmd=batch HTTP/1.1" 200 42 "-" "mercurial/proto-1.0" 10.10.168.170 - - [28/Oct/2013:11:49:19 +0100] "GET /hg/testagt?cmd=getbundle HTTP/1.1" 200 61184 "-" "mercurial/proto-1.0" 10.10.168.170 - - [28/Oct/2013:11:49:22 +0100] "GET /hg/testagt?cmd=listkeys HTTP/1.1" 200 15 "-" "mercurial/proto-1.0" 10.10.168.170 - - [28/Oct/2013:11:49:24 +0100] "GET /hg/testagt?cmd=listkeys HTTP/1.1" 200 - "-" "mercurial/proto-1.0" In this last example, you can see only one 401 response.
author Stéphane Klein <contact@stephane-klein.info>
date Fri, 20 Dec 2013 14:56:05 +0100
parents 25e572394f5c
children b723f05ec49b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2953
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
1 # strutil.py - string utilities for Mercurial
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
2 #
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
3 # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
4 #
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8155
diff changeset
5 # This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 8225
diff changeset
6 # GNU General Public License version 2 or any later version.
2953
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
7
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
8 def findall(haystack, needle, start=0, end=None):
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
9 if end is None:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
10 end = len(haystack)
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
11 if end < 0:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
12 end += len(haystack)
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
13 if start < 0:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
14 start += len(haystack)
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
15 while start < end:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
16 c = haystack.find(needle, start, end)
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
17 if c == -1:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
18 break
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
19 yield c
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
20 start = c + 1
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
21
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
22 def rfindall(haystack, needle, start=0, end=None):
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
23 if end is None:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
24 end = len(haystack)
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
25 if end < 0:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
26 end += len(haystack)
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
27 if start < 0:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
28 start += len(haystack)
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
29 while end >= 0:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
30 c = haystack.rfind(needle, start, end)
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
31 if c == -1:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
32 break
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
33 yield c
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
34 end = c - 1