Пример #1
0
 private void FireSendingRequest()
 {
     if (!this.fireSendingRequestMethodCalled)
     {
         this.fireSendingRequestMethodCalled = true;
         Dictionary <string, string> cachedHeaders = null;
         if (this.requestInfo.HasSendingRequestEventHandlers)
         {
             cachedHeaders = new Dictionary <string, string>(StringComparer.Ordinal);
             foreach (KeyValuePair <string, string> pair in this.Headers)
             {
                 cachedHeaders.Add(pair.Key, pair.Value);
             }
             cachedHeaders.Add("Content-Length", this.httpRequest.ContentLength.ToString(CultureInfo.InvariantCulture));
         }
         if ((string.CompareOrdinal("GET", this.Method) != 0) && (string.CompareOrdinal("DELETE", this.Method) == 0))
         {
             this.httpRequest.ContentType   = null;
             this.httpRequest.ContentLength = 0L;
         }
         if (this.requestInfo.HasSendingRequestEventHandlers)
         {
             WebHeaderCollection     requestHeaders = this.httpRequest.Headers;
             SendingRequestEventArgs eventArgs      = new SendingRequestEventArgs(this.httpRequest, requestHeaders);
             this.requestInfo.FireSendingRequest(eventArgs);
             if (!object.ReferenceEquals(eventArgs.Request, this.httpRequest))
             {
                 this.httpRequest = (System.Net.HttpWebRequest)eventArgs.Request;
             }
             SetHeaderValues(this, cachedHeaders);
         }
         this.requestInfo.InternalSendRequest(this.httpRequest);
     }
 }
Пример #2
0
        void context_SendingRequest(object sender, SendingRequestEventArgs e)
        {
            // NOTE: the http method is always GET - the SendingRequest event is fired
            // before ADO.Net data services sets the apropriate VERB.

            this.textBox1.AppendText(e.Request.FormatRequest());
        }
Пример #3
0
        private void SendingRequestWithNewVersion(object sender, SendingRequestEventArgs e)
        {
            HttpWebRequest request = e.Request as HttpWebRequest;

            // Apply the new storage version as a header value
            request.Headers[StorageVersionHeader] = August2011Version;
        }
Пример #4
0
        /// <summary>
        /// Fires the SendingRequest event.
        /// </summary>
        /// <param name="eventArgs">SendingRequestEventArgs instance containing all information about the request.</param>
        internal void FireSendingRequest(SendingRequestEventArgs eventArgs)
        {
#if DEBUG
            Version requestVersion = this.GetRequestVersion(eventArgs.RequestHeaders);
            Debug.Assert(this.UserModifiedRequestInBuildingRequest || requestVersion == null || requestVersion <= this.MaxProtocolVersionAsVersion, "requestVersion must not be greater than the maxProtocolVersion");
            Debug.Assert(this.UserModifiedRequestInBuildingRequest || eventArgs.RequestHeaders[XmlConstants.HttpMaxDataServiceVersion] == this.MaxProtocolVersionAsVersion.ToString() + Util.VersionSuffix, "requestMDSV must be set to the maxProtocolVersion");
#endif
            this.Context.FireSendingRequest(eventArgs);
        }
        void proxy_SendingRequest(object sender, SendingRequestEventArgs e)
        {
            // get the settings...
            DownloadSettings settings = GetDownloadSettings();
            if (settings == null)
                throw new InvalidOperationException("'settings' is null.");

            // walk...
            foreach (string name in settings.ExtraHeaders.Keys)
                e.RequestHeaders[name] = settings.ExtraHeaders[name];
        }
        private void OnSendingRequest(object sender, SendingRequestEventArgs e)
        {
            var httpRequest = e.Request as HttpWebRequest;
            httpRequest.Proxy = HttpWebRequest.DefaultWebProxy;
            httpRequest.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;

            if (httpRequest != null)
            {
                httpRequest.UserAgent = HttpUtility.CreateUserAgentString("NuGet Package Explorer");
                httpRequest.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
            }
        }
        /// <summary>
        /// Event handler for the SendingRequest event of the Service Reference class
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static void service_SendingRequest(object sender, SendingRequestEventArgs e)
        {
            if (e.Request.RequestUri.ToString().ToUpper().Contains("DOL.GOV"))
            {
                //Get Uri (Without host name or http://
                string requestUri = e.Request.RequestUri.PathAndQuery;

                //Build a timestamp in the format required by the API. ISO-8601
                string Timestamp = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ");

                //Build the signature
                string signature = Hash(string.Format("{0}&Timestamp={1}&ApiKey={2}", requestUri, Timestamp, DOLApiKey), DOLSharedSecret);

                //Add the Authorization header
                e.RequestHeaders["Authorization"] = string.Format("Timestamp={0}&ApiKey={1}&Signature={2}", Timestamp, DOLApiKey, signature);
            }
        }
Пример #8
0
        /// <summary>
        /// Fire SendingRequest event if its conditions are met.
        /// If the user has a handler for BuildingRequest, we will throw.
        /// If the user has no BuildingRequest handlers but does have a SendingRequest2 handler, we silently do not fire this event (this is shipped 5.0 behavior).
        /// </summary>
        private void FireSendingRequest()
        {
            // Do not fire SendingRequest event when user tries to wrap the HttpWebRequestMessage
            if (this.fireSendingRequestMethodCalled || this.requestInfo == null)
            {
                return;
            }

            // We need to set this before SendingRequest event is fired so that
            // GetStream method can throw if it is called from SendingRequest event.
            this.fireSendingRequestMethodCalled = true;

            HeaderCollection cachedHeaders = null;

            if (this.requestInfo.HasSendingRequestEventHandlers)
            {
                // Before firing SendingRequest event, we need to cache all the header values so that
                // we can reset them to the original values after SendingRequest event has been fired.
                cachedHeaders = new HeaderCollection();
                foreach (var header in this.Headers)
                {
                    cachedHeaders.SetHeader(header.Key, header.Value);
                }
#if PORTABLELIB
                cachedHeaders.SetHeader(XmlConstants.HttpContentLength, this.httpRequest.Headers[XmlConstants.HttpContentLength]);
#endif
#if !ASTORIA_LIGHT && !PORTABLELIB
                // Content-Length and accept header does not show up in the header collection at all.
                // Hence adding it explicitly, since we reset the content length header
                // after firing SendingRequest event
                cachedHeaders.SetHeader(XmlConstants.HttpContentLength, this.httpRequest.ContentLength.ToString(CultureInfo.InvariantCulture));
#endif
            }

            // Fires whenever a new HttpWebRequest has been created
            // The event fires early - before the client library sets many of its required property values.
            // This ensures the client library has the last say on the value of mandated properties
            // such as the HTTP verb  being used for the request.
            if (this.requestInfo.HasSendingRequestEventHandlers)
            {
                System.Net.WebHeaderCollection requestHeaders;
#if !ASTORIA_LIGHT
                requestHeaders = this.httpRequest.Headers;
                SendingRequestEventArgs args = new SendingRequestEventArgs(this.httpRequest, requestHeaders);
#else
                requestHeaders = this.httpRequest.CreateEmptyWebHeaderCollection();
                /* Also set header for SL, MaxDataServcieVersion is required header */
                foreach (var head in this.Headers)
                {
                    if (head.Key == XmlConstants.HttpMaxDataServiceVersion)
                    {
                        requestHeaders[XmlConstants.HttpMaxDataServiceVersion] = head.Value;
                        break;
                    }
                }

                SendingRequestEventArgs args = new SendingRequestEventArgs(null, requestHeaders);
#endif
                this.requestInfo.FireSendingRequest(args);

#if !ASTORIA_LIGHT
                if (!Object.ReferenceEquals(args.Request, this.httpRequest))
                {
                    this.httpRequest = (System.Net.HttpWebRequest)args.Request;
                }
#else
                // apply all headers to the request
                foreach (string key in requestHeaders.AllKeys)
                {
                    this.httpRequest.Headers[key] = requestHeaders[key];
                }
#endif
                HttpWebRequestMessage.SetHeaderValues(this, cachedHeaders, this.Method);
            }
        }
Пример #9
0
 internal void FireSendingRequest(SendingRequestEventArgs eventArgs)
 {
     this.context.FireSendingRequest(eventArgs);
 }
Пример #10
0
 private static void OnSendingRequest(object sender, SendingRequestEventArgs e)
 {
     // Add an Authorization header that contains an OAuth WRAP access token to the request.
     e.RequestHeaders.Add("Authorization", "Bearer " + _accessToken);
 }
Пример #11
0
 private void FireSendingRequest()
 {
     if (!this.fireSendingRequestMethodCalled)
     {
         this.fireSendingRequestMethodCalled = true;
         Dictionary<string, string> cachedHeaders = null;
         if (this.requestInfo.HasSendingRequestEventHandlers)
         {
             cachedHeaders = new Dictionary<string, string>(StringComparer.Ordinal);
             foreach (KeyValuePair<string, string> pair in this.Headers)
             {
                 cachedHeaders.Add(pair.Key, pair.Value);
             }
             cachedHeaders.Add("Content-Length", this.httpRequest.ContentLength.ToString(CultureInfo.InvariantCulture));
         }
         if ((string.CompareOrdinal("GET", this.Method) != 0) && (string.CompareOrdinal("DELETE", this.Method) == 0))
         {
             this.httpRequest.ContentType = null;
             this.httpRequest.ContentLength = 0L;
         }
         if (this.requestInfo.HasSendingRequestEventHandlers)
         {
             WebHeaderCollection requestHeaders = this.httpRequest.Headers;
             SendingRequestEventArgs eventArgs = new SendingRequestEventArgs(this.httpRequest, requestHeaders);
             this.requestInfo.FireSendingRequest(eventArgs);
             if (!object.ReferenceEquals(eventArgs.Request, this.httpRequest))
             {
                 this.httpRequest = (System.Net.HttpWebRequest) eventArgs.Request;
             }
             SetHeaderValues(this, cachedHeaders);
         }
         this.requestInfo.InternalSendRequest(this.httpRequest);
     }
 }
 /// <summary>
 /// Event handler for getting a token from ACS
 /// </summary>
 public static void GetTokenWithWritePermission(object sender, SendingRequestEventArgs args)
 {
     GetTokenWithWritePermission((HttpWebRequest)args.Request);
 }
Пример #13
0
 void Container_SendingRequest(object sender, SendingRequestEventArgs e)
 {
     Console.WriteLine("\t{0} {1}", e.Request.Method, e.Request.RequestUri.ToString());
     //ICredentials credentials = new System.Net.NetworkCredential("username", "password");
     //e.Request.Proxy = new System.Net.WebProxy("http://localhost:666", true, null, credentials);
 }
        /// <summary>Callback on DataContext object sending request.</summary>
        /// <param name="sender">The sender. </param>
        /// <param name="e">The <see cref="System.Data.Services.Client.SendingRequestEventArgs"/> instance containing the event data. </param>
        private void DataContextSendingRequest(object sender, SendingRequestEventArgs e)
        {
            var request = e.Request as HttpWebRequest;

            Debug.Assert(request != null, "request != null");
            request.Headers.Add(Constants.HeaderConstants.StorageVersionHeader, Request.GetTargetVersion());

            this.StorageCredentials.SignRequestLite(request);

            CommonUtils.ApplyRequestOptimizations(request, -1);
        }
        /// <summary>
        /// Callback on DataContext object sending request.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Data.Services.Client.SendingRequestEventArgs"/> instance containing the event data.</param>
        private void DataContextSendingRequest(object sender, SendingRequestEventArgs e)
        {
            HttpWebRequest request = e.Request as HttpWebRequest;

            request.Headers.Add(
                Protocol.Constants.HeaderConstants.StorageVersionHeader,
                Protocol.Request.GetTargetVersion());

            StorageCredentials.SignRequestLite(request);

            CommonUtils.ApplyRequestOptimizations(request, -1);
        }
Пример #16
0
 internal void FireSendingRequest(SendingRequestEventArgs eventArgs)
 {
     this.context.FireSendingRequest(eventArgs);
 }
 private void OnSendingRequest(object sender, SendingRequestEventArgs e)
 {
     // Initialize the request
     _httpClient.InitializeRequest(e.Request, acceptCompression: true);
 }
 private static void ConfigurableDataServiceContextSendingRequest(object sender, SendingRequestEventArgs e)
 {
 }
 /// <summary>
 /// Adds to request headers.
 /// </summary>
 /// <param name="sendingRequestEventArgs">The <see cref="System.Data.Services.Client.SendingRequestEventArgs"/> instance containing the event data.</param>
 private void AddToRequestHeaders(SendingRequestEventArgs sendingRequestEventArgs)
 {
     this.AddVersionToRequest(sendingRequestEventArgs.Request);
 }
 /// <summary>
 /// Adds the request version.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="System.Data.Services.Client.SendingRequestEventArgs"/> instance containing the event data.</param>
 private void AddRequestVersion(object sender, SendingRequestEventArgs e)
 {
     this.AddToRequestHeaders(e);
 }
 void MyDataServiceContext_SendingRequest(object sender, SendingRequestEventArgs e)
 {
     // Write some logging information to the page to demonstrate the ADO.NET Data Service requests
     // that are being made.
     HttpContext.Current.Response.Write("<div class=\"DD\">" + e.Request.RequestUri + "</div>");
 }
Пример #22
0
 void DS_SendingRequest(object sender, SendingRequestEventArgs e)
 {
     //if (_modelLoadCompleteEvent.WaitOne(30000) == false)                 throw new TimeoutException("The load edm model method has`t been returned.");
     _modelLoadCompleteEvent.WaitOne();
     e.Request.Headers.Add("Authorization", "Bearer " + GetRawToken());
 }
Пример #23
0
 public void OnSendingRequest(object sender, SendingRequestEventArgs e)
 {
     string str = this.Authenticate("");
     e.RequestHeaders.Add("Authorization", "OAuth " + str);
 }
 private void OnSendingRequest(object sender, SendingRequestEventArgs e)
 {
     // Initialize the request
     _httpClient.InitializeRequest(e.Request);
 }
Пример #25
0
 void context_SendingRequest(object sender, SendingRequestEventArgs e)
 {
     txtblkInstructions.Text += " : Sending..";
 }
 private void AttachTokenWithWritePermissions(object sender, SendingRequestEventArgs args)
 {
     this.AttachTokenWithWritePermissions((HttpWebRequest)args.Request);
 }
        /// <summary>
        /// Callback on DataContext object sending request.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Data.Services.Client.SendingRequestEventArgs"/> instance containing the event data.</param>       
        private void TableServiceContext_SendingRequest(object sender, SendingRequestEventArgs e)
        {
            HttpWebRequest request = e.Request as HttpWebRequest;
            
            // Check timeout
            int timeoutDex = request.RequestUri.Query.LastIndexOf("&timeout=", System.StringComparison.Ordinal);
            if (timeoutDex > 0)
            {
                timeoutDex += 9; // Magic number -> length of "&timeout="
                int endDex = request.RequestUri.Query.IndexOf('&', timeoutDex);
                string timeoutString = endDex > 0
                                           ? request.RequestUri.Query.Substring(timeoutDex, endDex - timeoutDex)
                                           : request.RequestUri.Query.Substring(timeoutDex);

                int result = -1;
                if (int.TryParse(timeoutString, out result) && result > 0)
                {
                    request.Timeout = result * 1000; // Convert to ms
                }
            }

            // Sign request
            if (this.ServiceClient.Credentials.IsSharedKey)
            {
                this.AuthenticationHandler.SignRequest(request, null /* operationContext */);
            }
            else if (this.ServiceClient.Credentials.IsSAS)
            {
                Uri transformedUri = this.ServiceClient.Credentials.TransformUri(request.RequestUri);

                // Recreate the request
                HttpWebRequest newRequest = WebRequest.Create(transformedUri) as HttpWebRequest;
                TableUtilities.CopyRequestData(newRequest, request);
                e.Request = newRequest;
                request = newRequest;
            }

            lock (this.cancellationLock)
            {
                if (this.cancellationRequested)
                {
                    throw new OperationCanceledException(SR.OperationCanceled);
                }

                this.currentRequest = request;
            }

            if (!this.ServiceClient.Credentials.IsSAS)
            {
                // SAS will be handled directly by the queries themselves prior to transformation
                request.Headers.Add(
                    Constants.HeaderConstants.StorageVersionHeader,
                    Constants.HeaderConstants.TargetStorageVersion);
            }

            CommonUtility.ApplyRequestOptimizations(request, -1);

            if (this.sendingSignedRequestAction != null)
            {
                this.sendingSignedRequestAction(request);
            }
        }
 /// <summary> 
 /// When sending Http Data requests to the Azure Marketplace, inject authorization header based on the current Access token.
 /// </summary> 
 /// <param name="sender">Event sender.</param> 
 /// <param name="e">Event arguments.</param> 
 private void OnSendingRequest(object sender, SendingRequestEventArgs e)
 {
     this.AddAccessTokenToRequest(e.Request);
 }
Пример #29
0
        /// <summary>
        /// Handler that appends the token to every data access context request.
        /// </summary>
        /// <param name="sender">The issuer of the request.</param>
        /// <param name="e">Additional info for the request.</param>
        private void BeforeSendingRequest(object sender, SendingRequestEventArgs e)
        {
            HttpWebRequest request = e.Request as HttpWebRequest;

            if (request != null)
            {
                this.OnEnhanceRequest(request);
            }
        }
 private void OnSendingRequest(object sender, SendingRequestEventArgs e)
 {
     _client.InitializeRequest(e.Request);
 }