Esempio n. 1
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);
        }
Esempio n. 2
0
        protected internal sealed override void GetResponseHeaders(CefResponse response, ref long responseLength, ref string redirectUrl)
        {
            response.Status   = (int)this.StatusCode;
            response.Charset  = "utf-8";
            response.MimeType = this.MimeType;
            responseLength    = _data.Length;

            if (_headers != null && _headers.Count > 0)
            {
                using (var map = new CefStringMultimap())
                {
                    map.Add(_headers);
                    response.SetHeaderMap(map);
                }
            }
        }