[Qtwebengine] QWebEngineUrlRequestInterceptor does not set HTTP headers for request resulted from redirect

Alon Bar-Lev alon.barlev at gmail.com
Wed Dec 13 15:26:30 CET 2023


Hello Allan,

Thank you for the quick response :)

On Wed, Dec 13, 2023 at 3:48 PM Allan Jensen <Allan.Jensen at qt.io> wrote:

> Sounds like you are looking for a way to add request headers. Not sure
> there
> is header in a redirect response, that would trigger the client to use the
> header to the redirected request.
>

Sure there are headers in a redirect request... if the useragent sets
them...
For example, Firefox/Chrome sets these when performing the SSO.


> We had patches for 6.6 to add request headers to the API, but it wasn't
> working consistently. If you could open a bug with you needs to we perhaps
> improve on the old patch and create something suited for your needs.
>

I do not understand, it does work setting request headers for regular
responses with the current implementation.
And you are correct, this is not consistent as the redirect is not
covered... but this is the current implementation.
What does this patch do?

BTW: there is also a problem in setting cookies in
QWebEngineUrlRequestInterceptor headers set of "Cookie" is working only
when no cookies managed by the cookie store, cookie store overwrite this if
it has something but if I put a new cookie in the store within the
interceptor these are ignored. I think there should be some generic
interceptor that receives the raw request just before it leaves the user
agent.


> best regards,
> Allan
>
>
>
> On Mittwoch, 13. Dezember 2023 13:06:15 CET Alon Bar-Lev wrote:
>
> Hello,
>
>
> I am trying to use the QWebEngine to perform SSO based on the Microsoft
> ProofOfPossession protocol in which I need to set headers requests
> including
> redirects.
>
>
> It seems like the QWebEngineUrlRequestInterceptor works and sets the
> headers
> for most request, however, it is ignoring the set headers when the request
> is
> a redirect request. Aka a site returns 302 and as result a GET request
> should
> be invoked with additional headers.
>
>
>
> I could not find how I can inject headers in any other way to requests.
>
>
>
> I am using PyQt6_WebEngine-6.6.0 think it is not related to python wrapper
>
> I also tested PyQtWebEngine-5.15.6 it behaves the same.
>
>
> Any clue? Any other ideas? How can I set headers of all requests?
>
>
> Thanks,
> Alon
>
>
>
> ---
>
>
> class WebEngineUrlRequestInterceptor(QWebEngineUrlRequestInterceptor):
>     def interceptRequest(self, info):
>             info.setHttpHeader("test1".encode("ascii"),
> "value1".encode("ascii"))
>
>
> class Example(QMainWindow):
>     def __init__(self):
>         super(Example, self).__init__()
>
>
>         self.profile = QWebEngineProfile()
>         self.interceptor = WebEngineUrlRequestInterceptor()
>         self.profile.setUrlRequestInterceptor(self.interceptor)
>         self.page = QWebEnginePage(self.profile)
>         self.webEngineView = QWebEngineView(self.page, self)
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qtwebengine/attachments/20231213/5431dad5/attachment.htm>


More information about the QtWebEngine mailing list