Beispiel #1
0
        private async Task Notify(Publication publication, Subscription subscription, HttpContent content)
        {
            // must clone because sending each payload will cause the http client to
            // dispose it, leading to an exception on subsequent notifications
            var contentClone = await content.Clone();

            var request = new HttpRequestMessage(HttpMethod.Post, subscription.Callback)
            {
                Content = contentClone
            };

            request.Headers.Add("link", $"<{publication.HubLocation} />; rel=\"hub\", <{publication.Topic} />; rel=\"self\""); // required headers

            if (!string.IsNullOrEmpty(subscription.Secret))
            {
                var secret = _cryptoFunctions.Decrypt(subscription.Secret, subscription.Callback.ToString());

                /* Section 8 */
                var hash = _cryptoFunctions.GetHmacSha1Hash(
                    await contentClone.ReadAsByteArrayAsync(),
                    secret);

                request.Headers.Add("X-Hub-Signature", hash);
            }

            var response = await _httpClient.SendAsync(request);

            if (!response.IsSuccessStatusCode)
            {
                var message = Strings.Error_SubscriberPublishFailed;
                if (response.Content != null)
                {
                    message = $"{(int)response.StatusCode}:{await response.Content.ReadAsStringAsync()}";
                }

                var args = new PublishNotificationFailureEventArgs(subscription, message);
                OnNotifyFailed(args);
            }
        }
Beispiel #2
0
 private void OnNotifyFailed(PublishNotificationFailureEventArgs args)
 {
     PublishNotificationFailed?.Invoke(this, args);
 }