Implement {register,intecept}StreamProtocol

These new functions are more flexible than the other
{intercept,register}*ProtocoProtocol functions, since it allows the user to
return a node.js stream to feed the data to the protocol handler.

It also allows the user to specify a response header dictionary, which makes it
possible to correctly intercept any request made from renderers.
This commit is contained in:
Thiago de Arruda 2017-11-03 17:03:14 -03:00
parent 68f514b92f
commit 5ea3a5886b
4 changed files with 277 additions and 0 deletions

View file

@ -10,6 +10,7 @@
#include "atom/browser/net/url_request_async_asar_job.h"
#include "atom/browser/net/url_request_buffer_job.h"
#include "atom/browser/net/url_request_fetch_job.h"
#include "atom/browser/net/url_request_stream_job.h"
#include "atom/browser/net/url_request_string_job.h"
#include "atom/common/native_mate_converters/callback.h"
#include "atom/common/native_mate_converters/value_converter.h"
@ -208,6 +209,8 @@ void Protocol::BuildPrototype(
&Protocol::RegisterProtocol<URLRequestAsyncAsarJob>)
.SetMethod("registerHttpProtocol",
&Protocol::RegisterProtocol<URLRequestFetchJob>)
.SetMethod("registerStreamProtocol",
&Protocol::RegisterProtocol<URLRequestStreamJob>)
.SetMethod("unregisterProtocol", &Protocol::UnregisterProtocol)
.SetMethod("isProtocolHandled", &Protocol::IsProtocolHandled)
.SetMethod("interceptStringProtocol",
@ -218,6 +221,8 @@ void Protocol::BuildPrototype(
&Protocol::InterceptProtocol<URLRequestAsyncAsarJob>)
.SetMethod("interceptHttpProtocol",
&Protocol::InterceptProtocol<URLRequestFetchJob>)
.SetMethod("interceptStreamProtocol",
&Protocol::InterceptProtocol<URLRequestStreamJob>)
.SetMethod("uninterceptProtocol", &Protocol::UninterceptProtocol);
}