diff --git a/Interfaces/IXBaseIdentityHttpProvider.cs b/Interfaces/IXBaseIdentityHttpProvider.cs
index 9971946..96c1a4f 100644
--- a/Interfaces/IXBaseIdentityHttpProvider.cs
+++ b/Interfaces/IXBaseIdentityHttpProvider.cs
@@ -1,4 +1,5 @@
using System;
+using System.IO;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
@@ -107,6 +108,7 @@ namespace xIdentityService.Interfaces
/// Access a Get Request Stream as AsyncEnumerable ...
///
///
+ ///
///
///
///
@@ -115,8 +117,9 @@ namespace xIdentityService.Interfaces
///
///
///
- IAsyncEnumerable StreamData(
+ Task StreamData(
Enum endpoint,
+ int bufferLength = 8194,
bool addXPoweredValue = true,
XTokenResponse tokens = null,
IDictionary @params = null,
@@ -168,11 +171,13 @@ namespace xIdentityService.Interfaces
/// and Query Strings Attach ...
///
///
+ ///
///
///
///
string PrepareUrl(
Enum endpoint,
+ bool attachBaseUrl = false,
IDictionary @params = null,
IDictionary queryStrings = null
);
@@ -182,11 +187,13 @@ namespace xIdentityService.Interfaces
/// and Query Strings Attach ...
///
///
+ ///
///
///
///
string PrepareUrl(
string url,
+ bool attachBaseUrl = false,
IDictionary @params = null,
IDictionary queryStrings = null
);
diff --git a/Providers/XBaseIdentityHttpProvider.cs b/Providers/XBaseIdentityHttpProvider.cs
index 401a5bc..282a46a 100644
--- a/Providers/XBaseIdentityHttpProvider.cs
+++ b/Providers/XBaseIdentityHttpProvider.cs
@@ -1,4 +1,5 @@
using System;
+using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
@@ -19,6 +20,8 @@ using xIdentityService.Constants;
using xIdentityService.Interfaces;
using xIdentityService.Models;
using xIdentityService.Extensions;
+using System.Diagnostics.Tracing;
+using MySqlX.XDevAPI.Common;
namespace xIdentityService.Providers
{
@@ -132,7 +135,7 @@ namespace xIdentityService.Providers
//
httpClient.DefaultRequestHeaders
.Add(
- XAuthorization.AccessToken,
+ XAuthorization.Header,
$"{XAuthentication.BEARER} {tokens.AccessToken}");
}
@@ -257,9 +260,9 @@ namespace xIdentityService.Providers
{
//
var url = PrepareUrl(
- endpoint,
- @params,
- queryStrings
+ @params: @params,
+ endpoint: endpoint,
+ queryStrings: queryStrings
);
//
@@ -456,6 +459,7 @@ namespace xIdentityService.Providers
/// Access a Get Request Stream as AsyncEnumerable ...
///
///
+ ///
///
///
///
@@ -464,8 +468,9 @@ namespace xIdentityService.Providers
///
///
///
- public async IAsyncEnumerable StreamData(
+ public async Task StreamData(
Enum endpoint,
+ int bufferLength = 8194,
bool addXPoweredValue = true,
XTokenResponse tokens = null,
IDictionary @params = null,
@@ -477,9 +482,10 @@ namespace xIdentityService.Providers
{
//
var url = PrepareUrl(
- endpoint,
- @params,
- queryStrings
+ @params: @params,
+ endpoint: endpoint,
+ attachBaseUrl: true,
+ queryStrings: queryStrings
);
var client = GetHttpClient(tokens);
if (addXPoweredValue)
@@ -488,7 +494,8 @@ namespace xIdentityService.Providers
client.DefaultRequestHeaders
.Add(
XAuthorization.XPoweredBy,
- XPoweredValue);
+ XPoweredValue
+ );
}
//
@@ -499,16 +506,92 @@ namespace xIdentityService.Providers
new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("text/event-stream"));
//
- using (var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, cancellationToken))
- {
- //
- response.EnsureSuccessStatusCode();
- var stream = await response.Content.ReadAsStreamAsync();
- await foreach (var item in stream.ToAsyncEnumerable(cancellationToken: cancellationToken))
- {
- yield return item;
- }
- }
+ var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
+ response.EnsureSuccessStatusCode();
+
+ //
+ var stream = await response.Content.ReadAsStreamAsync();
+
+ //
+ return stream;
+
+ // using (var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, cancellationToken))
+ // {
+ // //
+ // int readedBuffers = 0;
+ // response.EnsureSuccessStatusCode();
+ // var buffer = new byte[bufferLength];
+ // var stream = await response.Content.ReadAsStreamAsync();
+
+ // //
+ // while ((readedBuffers = await stream.ReadAsync(buffer, 0, buffer.Length)) > 0)
+ // {
+ // //
+ // var content = buffer.FromBytes();
+ // Console.WriteLine(content);
+ // }
+
+ // // await foreach (var message in stream) {
+ // // Console.WriteLine(message);
+ // // }
+
+ // // await foreach (var item in stream.ToAsyncEnumerable(cancellationToken: cancellationToken))
+ // // {
+ // // //
+ // // Console.WriteLine(item);
+
+ // // // T value = item.IsNull()
+ // // // ? default(T)
+ // // // : item.FromBytes().FromJSON();
+
+ // // // //
+ // // // yield return value;
+ // // }
+ // }
+
+ ///
+ ///
+ ///
+ ///
+
+ //
+ // var eventSource = new EventSource(url);
+ // // eventSource.
+
+ // // var client = GetHttpClient(tokens);
+ // // if (addXPoweredValue)
+ // // {
+ // // //
+ // // client.DefaultRequestHeaders
+ // // .Add(
+ // // XAuthorization.XPoweredBy,
+ // // XPoweredValue);
+ // // }
+
+ // // //
+ // // // For SSE, you might want to set the Accept header, though not strictly necessary for just streaming
+ // // client.DefaultRequestHeaders.Accept.Clear();
+ // // client.DefaultRequestHeaders.Accept
+ // // .Add(
+ // // new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("text/event-stream"));
+
+ // // //
+ // // using (var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, cancellationToken))
+ // // {
+ // // //
+ // // response.EnsureSuccessStatusCode();
+ // // var stream = await response.Content.ReadAsStreamAsync();
+ // // await foreach (var item in stream.ToAsyncEnumerable(cancellationToken: cancellationToken))
+ // // {
+ // // //
+ // // T value = item.IsNull()
+ // // ? default(T)
+ // // : item.FromBytes().FromJSON();
+
+ // // //
+ // // yield return value;
+ // // }
+ // // }
}
///
@@ -748,11 +831,13 @@ namespace xIdentityService.Providers
/// and Query Strings Attach ...
///
///
+ ///
///
///
///
public string PrepareUrl(
Enum endpoint,
+ bool attachBaseUrl = false,
IDictionary @params = null,
IDictionary queryStrings = null
)
@@ -764,9 +849,10 @@ namespace xIdentityService.Providers
//
// Filling Parmas and Query Strings of Url ...
url = PrepareUrl(
- url,
- @params,
- queryStrings
+ url: url,
+ @params: @params,
+ queryStrings: queryStrings,
+ attachBaseUrl: attachBaseUrl
);
//
@@ -778,15 +864,31 @@ namespace xIdentityService.Providers
/// and Query Strings Attach ...
///
///
+ ///
///
///
///
public string PrepareUrl(
string url,
+ bool attachBaseUrl = false,
IDictionary @params = null,
IDictionary queryStrings = null
)
{
+ //
+ if (attachBaseUrl)
+ {
+ //
+ var baseUrl = BaseUrl;
+ if (!baseUrl.EndsWith("/"))
+ {
+ baseUrl = $"{baseUrl}/";
+ }
+
+ //
+ url = $"{baseUrl}{url}";
+ }
+
//
// Add Route Payloads ...
if (!@params.IsNull() && @params.Count > 0)