Exemple #1
0
 public unsafe void SetReferrer([Immutable] cef_string_t *referrer_url, CefReferrerPolicy policy)
 {
     fixed(cef_request_t *self = &this)
     {
         ((delegate * unmanaged[Stdcall] < cef_request_t *, cef_string_t *, CefReferrerPolicy, void >)set_referrer)(self, referrer_url, policy);
     }
 }
Exemple #2
0
        /// <summary>
        /// Send a GET request to the specified <see cref="Uri"/> and return the response body
        /// as a string in an asynchronous operation.
        /// </summary>
        /// <param name="requestUri">The <see cref="Uri"/> the request is sent to.</param>
        /// <param name="referrerUri">
        /// The <see cref="Uri"/> of the referring site for a request. Can be null.
        /// </param>
        /// <param name="referrerPolicy">
        /// The policy for how the Referrer HTTP header value will be sent during request.
        /// </param>
        /// <param name="headers">
        /// A <see cref="NameValueCollection"/> containing header name/value pairs associated with a request. Can be null.
        /// </param>
        /// <param name="cancellationToken">
        /// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public async Task <string> GetStringAsync(Uri requestUri, Uri referrerUri, CefReferrerPolicy referrerPolicy, NameValueCollection headers, CancellationToken cancellationToken)
        {
            CefNetWebRequest request = await GetAsync(requestUri, referrerUri, referrerPolicy, headers, cancellationToken).ConfigureAwait(false);

            AssertSuccess(request);

            Stream responseStream = request.GetResponseStream();

            if (responseStream is null)
            {
                return(string.Empty);
            }

            CefResponse response = request.Response;

            if (response is null)
            {
                return(null);
            }

            Encoding encoding;

            try
            {
                encoding = Encoding.GetEncoding(response.Charset);
            }
            catch (ArgumentException)
            {
                encoding = this.DefaultEncoding;
            }
            return(new StreamReader(responseStream, encoding).ReadToEnd());
        }
Exemple #3
0
        /// <summary>
        /// Set the referrer URL and policy. If non-empty the referrer URL must be
        /// fully qualified with an HTTP or HTTPS scheme component. Any username,
        /// password or ref component will be removed.
        /// </summary>
        public void SetReferrer(string referrerUrl, CefReferrerPolicy policy)
        {
            fixed(char *referrerUrl_str = referrerUrl)
            {
                var n_referrerUrl = new cef_string_t(referrerUrl_str, referrerUrl != null ? referrerUrl.Length : 0);

                cef_request_t.set_referrer(_self, &n_referrerUrl, policy);
            }
        }
Exemple #4
0
        /// <summary>
        /// Send a GET request to the specified <see cref="Uri"/> and return the response body
        /// as a <see cref="Stream"/> in an asynchronous operation.
        /// </summary>
        /// <param name="requestUri">The <see cref="Uri"/> the request is sent to.</param>
        /// <param name="referrerUri">
        /// The <see cref="Uri"/> of the referring site for a request. Can be null.
        /// </param>
        /// <param name="referrerPolicy">
        /// The policy for how the Referrer HTTP header value will be sent during request.
        /// </param>
        /// <param name="headers">
        /// A <see cref="NameValueCollection"/> containing header name/value pairs associated with a request. Can be null.
        /// </param>
        /// <param name="cancellationToken">
        /// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public async Task <Stream> GetStreamAsync(Uri requestUri, Uri referrerUri, CefReferrerPolicy referrerPolicy, NameValueCollection headers, CancellationToken cancellationToken)
        {
            if (requestUri is null)
            {
                throw new ArgumentNullException(nameof(requestUri));
            }

            CefNetWebRequest request = await GetAsync(requestUri, referrerUri, referrerPolicy, headers, cancellationToken).ConfigureAwait(false);

            AssertSuccess(request);

            return(request.GetResponseStream());
        }
Exemple #5
0
        /// <summary>
        /// Set the referrer URL and policy. If non-NULL the referrer URL must be fully
        /// qualified with an HTTP or HTTPS scheme component. Any username, password or
        /// ref component will be removed.
        /// </summary>
        public unsafe virtual void SetReferrer(string referrerUrl, CefReferrerPolicy policy)
        {
            fixed(char *s0 = referrerUrl)
            {
                var cstr0 = new cef_string_t {
                    Str = s0, Length = referrerUrl != null ? referrerUrl.Length : 0
                };

                NativeInstance->SetReferrer(&cstr0, policy);
            }

            GC.KeepAlive(this);
        }
Exemple #6
0
 /// <summary>
 /// Send a GET request to the specified <see cref="Uri"/> and return the response body
 /// as a <see cref="Byte"/> array in an asynchronous operation.
 /// </summary>
 /// <param name="requestUri">The <see cref="Uri"/> the request is sent to.</param>
 /// <param name="referrerUri">
 /// The <see cref="Uri"/> of the referring site for a request. Can be null.
 /// </param>
 /// <param name="referrerPolicy">
 /// The policy for how the Referrer HTTP header value will be sent during request.
 /// </param>
 /// <param name="headers">
 /// A <see cref="NameValueCollection"/> containing header name/value pairs associated with a request. Can be null.
 /// </param>
 /// <param name="cancellationToken">
 /// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
 /// </param>
 /// <returns>The task object representing the asynchronous operation.</returns>
 public async Task <byte[]> GetDataAsync(Uri requestUri, Uri referrerUri, CefReferrerPolicy referrerPolicy, NameValueCollection headers, CancellationToken cancellationToken)
 {
     using (Stream stream = await GetStreamAsync(requestUri, referrerUri, referrerPolicy, headers, cancellationToken).ConfigureAwait(false))
     {
         if (stream is MemoryStream mem && mem.Capacity == mem.Length)
         {
             return(mem.GetBuffer());
         }
         var buffer = new byte[stream.Length];
         if (buffer.Length != await stream.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false))
         {
             throw new InvalidOperationException();
         }
         return(buffer);
     }
 }
Exemple #7
0
        /// <summary>
        /// Send a GET request to the specified <see cref="Uri"/>.
        /// </summary>
        /// <param name="requestUri">
        /// The <see cref="Uri"/> the request is sent to.
        /// </param>
        /// <param name="referrerUri">
        /// The <see cref="Uri"/> of the referring site for a request. Can be null.
        /// </param>
        /// <param name="referrerPolicy">
        /// The policy for how the Referrer HTTP header value will be sent during request.
        /// </param>
        /// <param name="headers">
        /// A <see cref="NameValueCollection"/> containing header name/value pairs associated with a request. Can be null.
        /// </param>
        /// <param name="cancellationToken">
        /// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        /// <exception cref="ArgumentNullException">The <see cref="requestUri"/> parameter is null.</exception>
        public async Task <CefNetWebRequest> GetAsync(Uri requestUri, Uri referrerUri, CefReferrerPolicy referrerPolicy, NameValueCollection headers, CancellationToken cancellationToken)
        {
            if (requestUri is null)
            {
                throw new ArgumentNullException(nameof(requestUri));
            }

            var r = new CefRequest();

            r.Flags = (int)this.RequestFlags;
            r.Url   = requestUri.AbsoluteUri;
            if (referrerUri != null)
            {
                r.SetReferrer(referrerUri.AbsoluteUri, referrerPolicy);
            }
            if (headers != null && headers.Count > 0)
            {
                using (var map = new CefStringMultimap())
                {
                    map.Add(headers);
                    r.SetHeaderMap(map);
                }
            }

            var request = new CefNetWebRequest(this);
            await request.SendAsync(r, _context, cancellationToken);

            return(request);
        }
Exemple #8
0
        /// <summary>
        /// Send a POST request to the specified <see cref="Uri"/> and return the response body
        /// as a <see cref="Stream"/> in an asynchronous operation.
        /// </summary>
        /// <param name="requestUri">The <see cref="Uri"/> the request is sent to.</param>
        /// <param name="referrerUri">
        /// The <see cref="Uri"/> of the referring site for a request. Can be null.
        /// </param>
        /// <param name="referrerPolicy">
        /// The policy for how the Referrer HTTP header value will be sent during request.
        /// </param>
        /// <param name="headers">
        /// A <see cref="NameValueCollection"/> containing header name/value pairs associated with a request. Can be null.
        /// </param>
        /// <param name="content">The request content sent to the specified <see cref="Uri"/>.</param>
        /// <param name="cancellationToken">
        /// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public async Task <Stream> PostReadStreamAsync(Uri requestUri, Uri referrerUri, CefReferrerPolicy referrerPolicy, CefPostData content, NameValueCollection headers, CancellationToken cancellationToken)
        {
            var request = await PostAsync(requestUri, referrerUri, referrerPolicy, content, headers, cancellationToken).ConfigureAwait(false);

            AssertSuccess(request);
            return(request.GetResponseStream());
        }
Exemple #9
0
 /// <summary>
 /// Send a GET request to the specified <see cref="Uri"/>.
 /// </summary>
 /// <param name="requestUri">
 /// The URI the request is sent to.
 /// </param>
 /// <param name="referrerUri">
 /// The URI of the referring site for a request. Can be null.
 /// </param>
 /// <param name="referrerPolicy">
 /// The policy for how the Referrer HTTP header value will be sent during request.
 /// </param>
 /// <param name="headers">
 /// A <see cref="NameValueCollection"/> containing header name/value pairs associated with a request. Can be null.
 /// </param>
 /// <param name="cancellationToken">
 /// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
 /// </param>
 /// <returns>The task object representing the asynchronous operation.</returns>
 /// <exception cref="ArgumentNullException">The <see cref="requestUri"/> parameter is null.</exception>
 public Task <CefNetWebRequest> GetAsync(string requestUri, string referrerUri, CefReferrerPolicy referrerPolicy, NameValueCollection headers, CancellationToken cancellationToken)
 {
     return(GetAsync(new Uri(requestUri, UriKind.Absolute), referrerUri is null ? null : new Uri(referrerUri, UriKind.Absolute), referrerPolicy, headers, cancellationToken));
 }
        public static void set_referrer(cef_request_t *self, cef_string_t *referrer_url, CefReferrerPolicy policy)
        {
            set_referrer_delegate d;
            var p = self->_set_referrer;

            if (p == _p8)
            {
                d = _d8;
            }
            else
            {
                d = (set_referrer_delegate)Marshal.GetDelegateForFunctionPointer(p, typeof(set_referrer_delegate));
                if (_p8 == IntPtr.Zero)
                {
                    _d8 = d; _p8 = p;
                }
            }
            d(self, referrer_url, policy);
        }
Exemple #11
0
 public unsafe extern void SetReferrer([Immutable] cef_string_t *referrer_url, CefReferrerPolicy policy);