Mercurial > p > roundup > code
comparison roundup/rest.py @ 6515:df4f955544aa
Explicitly match .json and .xml extension when used as last element of
the path component of a URI. This permits items like JWT that have multiple
'.' separated components to be passed in the path of the URI.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Wed, 20 Oct 2021 23:21:46 -0400 |
| parents | d5a3fe9ac12d |
| children | a22ea1a7e92c |
comparison
equal
deleted
inserted
replaced
| 6514:a036712c96f4 | 6515:df4f955544aa |
|---|---|
| 1959 # priority : extension from uri (/rest/data/issue.json), | 1959 # priority : extension from uri (/rest/data/issue.json), |
| 1960 # header (Accept: application/json, application/xml) | 1960 # header (Accept: application/json, application/xml) |
| 1961 # default (application/json) | 1961 # default (application/json) |
| 1962 ext_type = os.path.splitext(urlparse(uri).path)[1][1:] | 1962 ext_type = os.path.splitext(urlparse(uri).path)[1][1:] |
| 1963 | 1963 |
| 1964 # Use explicit list of extensions. Even if xml isn't supported | |
| 1965 # recognize it as a valid directive. | |
| 1966 if ext_type in ['json', 'xml']: | |
| 1967 # strip extension so uri make sense | |
| 1968 # .../issue.json -> .../issue | |
| 1969 uri = uri[:-(len(ext_type) + 1)] | |
| 1970 else: | |
| 1971 ext_type = None | |
| 1972 | |
| 1964 # headers.get('Accept') is never empty if called here. | 1973 # headers.get('Accept') is never empty if called here. |
| 1965 # accept_type will be set to json if there is no Accept header | 1974 # accept_type will be set to json if there is no Accept header |
| 1966 # accept_type wil be empty only if there is an Accept header | 1975 # accept_type wil be empty only if there is an Accept header |
| 1967 # with invalid values. | 1976 # with invalid values. |
| 1968 data_type = ext_type or accept_type or headers.get('Accept') or "invalid" | 1977 data_type = ext_type or accept_type or headers.get('Accept') or "invalid" |
