proxy - C++ builder indy intercept IdHTTPProxyServer to insert header -
i want insert header of external script on https within browser. purpose utilize c++ builder idhttpproxyserver component. read document response event dont know how insert 1 simple .js. -> cause document property read only, on other side beforecommandhandler want append script (in code under utilize text insert simplicity)
how insert .js external script in c++ builder?
here done far.
void __fastcall tform5::idhttpproxyserver1httpresponse (tidhttpproxyservercontext *acontext) { memo1->lines->append("\non response!!!\n" + acontext->document); } void __fastcall tform5::idhttpproxyserver1beforecommandhandler (tidcmdtcpserver *asender, unicodestring &adata, tidcontext *acontext) { seek { memo1->lines->add(adata); unicodestring sa = adata; adata = l"<html>something</html>" + sa; } grab (int e) { messagebeep(100); } }
the tidhttpproxyserver::onbeforecommandhandler
event triggered before client's request processed. adata
parameter original request. event meant logging/altering commands before parsed.
the tidhttpproxyserver::onhttpbeforecommand
event triggered after client's request headers have been received before connection established target server , client's request body read , sent server.
the tidhttpproxyserver::onhttpresponse
event triggered after server's response headers have been received before response body read , sent client.
so none of events help you.
neither tidhttpproxyservercontext::document
property, matter. property not contain document data, assuming. contains server-relative url of document beingness requested instead.
to asking for, set tidhttpproxyserver::defaulttransfermode
property tmfulldocument
, utilize onhttpdocument
event. tidhttpproxyservercontext::transfersource
property tell if info coming client or server.
you have total access headers , body info , can modify them needed. create sure update tidhttpproxyservercontext.headers
, in particular content-length
header, if modify body data. body info provided tstream
object (specifically, tmemorystream
). can either modify stream's content directly, or can create new tstream
object desired content (the vstream
parameter of event passed reference can re-assign it).
for example:
class="lang-cpp prettyprint-override">void __fastcall tform5::idhttpproxyserver1httpdocument(tidhttpproxyservercontext* acontext, tstream* &vstream) { if (acontext->transfersource == tsserver) { string s = readstringascontenttype(vstream, acontext->headers->values[l"content-type"], quotehttp); // not thread-safe! tidhttpproxyserver multi-threaded, // must synchronize main thread in order safely // update ui controls... // // memo1->text = s; s = l"<html>something</html>" + s; delete vstream; vstream = new tstringstream(s, sysutils::tencoding::utf8); acontext->headers->values[l"content-length"] = vstream->size; acontext->headers->params[l"content-type"][l"charset"] = l"utf-8"; } }
proxy c++builder indy
No comments:
Post a Comment