Details
Details
- Reviewers
ryanmce - Group Reviewers
hg-reviewers - Commits
- rHG67e9678efd98: httppeer: always produce native str header keys and values
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
( )
| ryanmce |
| hg-reviewers |
| Lint Skipped |
| Unit Tests Skipped |
| def encodevalueinheaders(value, header, limit): | def encodevalueinheaders(value, header, limit): | ||||
| """Encode a string value into multiple HTTP headers. | """Encode a string value into multiple HTTP headers. | ||||
| ``value`` will be encoded into 1 or more HTTP headers with the names | ``value`` will be encoded into 1 or more HTTP headers with the names | ||||
| ``header-<N>`` where ``<N>`` is an integer starting at 1. Each header | ``header-<N>`` where ``<N>`` is an integer starting at 1. Each header | ||||
| name + value will be at most ``limit`` bytes long. | name + value will be at most ``limit`` bytes long. | ||||
| Returns an iterable of 2-tuples consisting of header names and values. | Returns an iterable of 2-tuples consisting of header names and | ||||
| values as native strings. | |||||
| """ | """ | ||||
| fmt = header + '-%s' | # HTTP Headers are ASCII. Python 3 requires them to be unicodes, | ||||
| valuelen = limit - len(fmt % '000') - len(': \r\n') | # not bytes. This function always takes bytes in as arguments. | ||||
| fmt = pycompat.strurl(header) + r'-%s' | |||||
| # Note: it is *NOT* a bug that the last bit here is a bytestring | |||||
| # and not a unicode: we're just getting the encoded length anyway, | |||||
| # and using an r-string to make it portable between Python 2 and 3 | |||||
| # doesn't work because then the \r is a literal backslash-r | |||||
| # instead of a carriage return. | |||||
| valuelen = limit - len(fmt % r'000') - len(': \r\n') | |||||
| result = [] | result = [] | ||||
| n = 0 | n = 0 | ||||
| for i in xrange(0, len(value), valuelen): | for i in xrange(0, len(value), valuelen): | ||||
| n += 1 | n += 1 | ||||
| result.append((fmt % str(n), value[i:i + valuelen])) | result.append((fmt % str(n), pycompat.strurl(value[i:i + valuelen]))) | ||||
| return result | return result | ||||
| def _wraphttpresponse(resp): | def _wraphttpresponse(resp): | ||||
| """Wrap an HTTPResponse with common error handlers. | """Wrap an HTTPResponse with common error handlers. | ||||
| This ensures that any I/O from any consumer raises the appropriate | This ensures that any I/O from any consumer raises the appropriate | ||||
| error and messaging. | error and messaging. | ||||