29 from cubicweb.uilib import remove_html_tags |
29 from cubicweb.uilib import remove_html_tags |
30 from cubicweb.utils import SizeConstrainedList, HTMLHead, make_uid |
30 from cubicweb.utils import SizeConstrainedList, HTMLHead, make_uid |
31 from cubicweb.view import STRICT_DOCTYPE, TRANSITIONAL_DOCTYPE_NOEXT |
31 from cubicweb.view import STRICT_DOCTYPE, TRANSITIONAL_DOCTYPE_NOEXT |
32 from cubicweb.web import (INTERNAL_FIELD_VALUE, LOGGER, NothingToEdit, |
32 from cubicweb.web import (INTERNAL_FIELD_VALUE, LOGGER, NothingToEdit, |
33 RequestError, StatusResponse) |
33 RequestError, StatusResponse) |
|
34 from cubicweb.web.http_headers import Headers |
34 |
35 |
35 _MARKER = object() |
36 _MARKER = object() |
36 |
37 |
37 |
38 |
38 def list_form_param(form, param, pop=False): |
39 def list_form_param(form, param, pop=False): |
86 self.next_tabindex = self.tabindexgen.next |
87 self.next_tabindex = self.tabindexgen.next |
87 # page id, set by htmlheader template |
88 # page id, set by htmlheader template |
88 self.pageid = None |
89 self.pageid = None |
89 self.datadir_url = self._datadir_url() |
90 self.datadir_url = self._datadir_url() |
90 self._set_pageid() |
91 self._set_pageid() |
|
92 # prepare output header |
|
93 self.headers_out = Headers() |
91 |
94 |
92 def _set_pageid(self): |
95 def _set_pageid(self): |
93 """initialize self.pageid |
96 """initialize self.pageid |
94 if req.form provides a specific pageid, use it, otherwise build a |
97 if req.form provides a specific pageid, use it, otherwise build a |
95 new one. |
98 new one. |
655 """return the value associated with the given input HTTP header, |
658 """return the value associated with the given input HTTP header, |
656 raise KeyError if the header is not set |
659 raise KeyError if the header is not set |
657 """ |
660 """ |
658 raise NotImplementedError() |
661 raise NotImplementedError() |
659 |
662 |
660 def set_header(self, header, value): |
663 def set_header(self, header, value, raw=True): |
661 """set an output HTTP header""" |
664 """set an output HTTP header""" |
662 raise NotImplementedError() |
665 if raw: |
|
666 # adding encoded header is important, else page content |
|
667 # will be reconverted back to unicode and apart unefficiency, this |
|
668 # may cause decoding problem (e.g. when downloading a file) |
|
669 self.headers_out.setRawHeaders(header, [str(value)]) |
|
670 else: |
|
671 self.headers_out.setHeader(header, value) |
663 |
672 |
664 def add_header(self, header, value): |
673 def add_header(self, header, value): |
665 """add an output HTTP header""" |
674 """add an output HTTP header""" |
666 raise NotImplementedError() |
675 # adding encoded header is important, else page content |
|
676 # will be reconverted back to unicode and apart unefficiency, this |
|
677 # may cause decoding problem (e.g. when downloading a file) |
|
678 self.headers_out.addRawHeader(header, str(value)) |
667 |
679 |
668 def remove_header(self, header): |
680 def remove_header(self, header): |
669 """remove an output HTTP header""" |
681 """remove an output HTTP header""" |
670 raise NotImplementedError() |
682 self.headers_out.removeHeader(header) |
671 |
683 |
672 def header_authorization(self): |
684 def header_authorization(self): |
673 """returns a couple (auth-type, auth-value)""" |
685 """returns a couple (auth-type, auth-value)""" |
674 auth = self.get_header("Authorization", None) |
686 auth = self.get_header("Authorization", None) |
675 if auth: |
687 if auth: |