|
Rank: Member Groups: Member
Joined: 6/13/2019 Posts: 18
|
Hello, I was wondering if it's possible to intercept and modify response headers before they're processed by the WebView? Thanks!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,218
|
Hi, No. It is not possible unless you uses a custom resource loader to replace the entire loader layer: https://www.essentialobjects.com/doc/webbrowser/advanced/resource_handler.aspxThe custom resource handler is extremely powerful feature but since the browser engine's built-in loader is highly optimized, replacing it with your loader can have serious performance implications. However if you only need to intercept a small number of request/response and let browser engine's loader handle the result, then the performance impact maybe negligible. Thanks!
|
|
Rank: Member Groups: Member
Joined: 6/13/2019 Posts: 18
|
Is there an example of how to handle all requests using the resource handler? For example, how would I handle the main page loading? Thanks!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,218
|
Hi,
You just do it your own way because you are taking over the whole loader layer. For example, you can use .NET built-in HttpClient class to download the main page from the "real" web server, or you can load a "fake" response from your database server. It's completely up to you We do not provide sample code on those parts because they are general .NET programming topics. However if you have any questions on how the custom resource handler works we will be happy to help.
Thanks!
|
|
Rank: Member Groups: Member
Joined: 6/13/2019 Posts: 18
|
Sorry, I should have been more clear. If I do load the content what do I do with it? Do I pass it through the response object in the resource handler, and how do I transfer everything (headers, cookies, content.. etc)? Thanks!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,218
|
Yes. You pretty much just transfer the header and contents over to the Rsponse object. You would transfer header entries through Response.Headers, and content through Response.OutputStream. The link we posted above already contains some sample code on how to do that.
In your case, if you want to insert/modify header entries, it would occur at this transferring stage. For example, you could only get header entry A, B and C from your real web server, but you can pass A, B, C and D to the Response object, here D is something else you wish to insert. Then the browser engine will think it has actually received 4 entries from the web server.
|
|
Rank: Member Groups: Member
Joined: 6/13/2019 Posts: 18
|
Excellent, thanks! Is there a way to access the raw post data? Right now I can see the .PostData collection but I can't submit that in my custom request, I need the raw byte array. Thanks!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,218
|
Hi,
PostData collection is where you would get the data. It contains multiple PostDataItem objects. You can then check each PostDataItem's Type, if it is "Byte", then you can get the data through the PostDataItem's Data property.
Note that in this case the byte array only represents the data for that PostDataItem. The same PostData collection may still contain other PostDataItem that does not have raw byte array associated to it (such as file upload). For such items you can't get the raw bytes.
Thanks!
|
|