cardinal_pythonlib.httpconst


Original code copyright (C) 2009-2022 Rudolf Cardinal (rudolf@pobox.com).

This file is part of cardinal_pythonlib.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


Constants for use with HTTP.

Many of these can be extracted:

import mimetypes
mimetypes.types_map['.zip']  # application/zip -- this is built in
mimetypes.types_map['.xlsx']  # fails
mimetypes.init()
mimetypes.types_map['.xlsx']  # application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
# ... must read some local thing...

Something’s changed – in Python 3.6.8, there’s no need for the init() call. There is also a guessing function, mimetypes.guess_type(); see https://docs.python.org/3.6/library/mimetypes.html.

>>> import mimetypes
>>> print(mimetypes.guess_type("thing.html"))
('text/html', None)
>>> print(mimetypes.guess_type("thing.xls"))
('application/vnd.ms-excel', None)
>>> print(mimetypes.guess_type("thing.xlsx"))
('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', None)
cardinal_pythonlib.httpconst.ContentType

alias of MimeType

class cardinal_pythonlib.httpconst.HttpMethod[source]

HTTP request methods, as upper-case constants.

class cardinal_pythonlib.httpconst.HttpStatus[source]

HTTP status codes.

https://en.wikipedia.org/wiki/List_of_HTTP_status_codes

classmethod is_good_answer(status: int) bool[source]

Is the given HTTP status code a satisfactory (happy) answer to a client’s request?

class cardinal_pythonlib.httpconst.MimeType[source]

Some MIME type constants. See also the Python standard library mimetypes; e.g.

import mimetypes
mimetypes.types_map['.pdf']  # 'application/pdf'

See: