Commit a99ff10a authored by Honfika's avatar Honfika

Show response data as image in test app, try-catch added to http2 test

parent 30920247
...@@ -36,13 +36,20 @@ ...@@ -36,13 +36,20 @@
</ListView> </ListView>
<TabControl Grid.Column="2" Grid.Row="0"> <TabControl Grid.Column="2" Grid.Row="0">
<TabItem Header="Session"> <TabItem Header="Session">
<Grid Background="Red" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition /> <RowDefinition />
<RowDefinition /> <RowDefinition />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBox x:Name="TextBoxRequest" Grid.Row="0" /> <TextBox x:Name="TextBoxRequest" Grid.Row="0" />
<TextBox x:Name="TextBoxResponse" Grid.Row="1" /> <TabControl Grid.Row="1">
<TabItem Header="Text">
<TextBox x:Name="TextBoxResponse" />
</TabItem>
<TabItem Header="Image">
<Image x:Name="ImageResponse" HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="None" />
</TabItem>
</TabControl>
</Grid> </Grid>
</TabItem> </TabItem>
</TabControl> </TabControl>
......
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Text; using System.Text;
...@@ -8,6 +9,7 @@ using System.Threading.Tasks; ...@@ -8,6 +9,7 @@ using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media.Imaging;
using Titanium.Web.Proxy.EventArguments; using Titanium.Web.Proxy.EventArguments;
using Titanium.Web.Proxy.Http; using Titanium.Web.Proxy.Http;
using Titanium.Web.Proxy.Models; using Titanium.Web.Proxy.Models;
...@@ -297,7 +299,8 @@ namespace Titanium.Web.Proxy.Examples.Wpf ...@@ -297,7 +299,8 @@ namespace Titanium.Web.Proxy.Examples.Wpf
var session = SelectedSession.HttpClient; var session = SelectedSession.HttpClient;
var request = session.Request; var request = session.Request;
var data = (request.IsBodyRead ? request.Body : null) ?? new byte[0]; var fullData = (request.IsBodyRead ? request.Body : null) ?? new byte[0];
var data = fullData;
bool truncated = data.Length > truncateLimit; bool truncated = data.Length > truncateLimit;
if (truncated) if (truncated)
{ {
...@@ -313,7 +316,8 @@ namespace Titanium.Web.Proxy.Examples.Wpf ...@@ -313,7 +316,8 @@ namespace Titanium.Web.Proxy.Examples.Wpf
TextBoxRequest.Text = sb.ToString(); TextBoxRequest.Text = sb.ToString();
var response = session.Response; var response = session.Response;
data = (response.IsBodyRead ? response.Body : null) ?? new byte[0]; fullData = (response.IsBodyRead ? response.Body : null) ?? new byte[0];
data = fullData;
truncated = data.Length > truncateLimit; truncated = data.Length > truncateLimit;
if (truncated) if (truncated)
{ {
...@@ -333,6 +337,19 @@ namespace Titanium.Web.Proxy.Examples.Wpf ...@@ -333,6 +337,19 @@ namespace Titanium.Web.Proxy.Examples.Wpf
} }
TextBoxResponse.Text = sb.ToString(); TextBoxResponse.Text = sb.ToString();
try
{
using (MemoryStream stream = new MemoryStream(fullData))
{
ImageResponse.Source =
BitmapFrame.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
}
}
catch
{
ImageResponse.Source = null;
}
} }
} }
} }
...@@ -245,8 +245,7 @@ namespace StreamExtended.Network ...@@ -245,8 +245,7 @@ namespace StreamExtended.Network
{ {
return -1; return -1;
} }
return streamBuffer[bufferPos + index]; return streamBuffer[bufferPos + index];
} }
...@@ -491,7 +490,7 @@ namespace StreamExtended.Network ...@@ -491,7 +490,7 @@ namespace StreamExtended.Network
if (bufferLength > 0) if (bufferLength > 0)
{ {
//normally we fill the buffer only when it is empty, but sometimes we need more data //normally we fill the buffer only when it is empty, but sometimes we need more data
//move the remanining data to the beginning of the buffer //move the remaining data to the beginning of the buffer
Buffer.BlockCopy(streamBuffer, bufferPos, streamBuffer, 0, bufferLength); Buffer.BlockCopy(streamBuffer, bufferPos, streamBuffer, 0, bufferLength);
} }
...@@ -516,7 +515,6 @@ namespace StreamExtended.Network ...@@ -516,7 +515,6 @@ namespace StreamExtended.Network
} }
return result; return result;
} }
/// <summary> /// <summary>
......
...@@ -47,8 +47,7 @@ namespace Titanium.Web.Proxy ...@@ -47,8 +47,7 @@ namespace Titanium.Web.Proxy
{ {
string connectHostname = null; string connectHostname = null;
TunnelConnectSessionEventArgs connectArgs = null; TunnelConnectSessionEventArgs connectArgs = null;
// Client wants to create a secure tcp tunnel (probably its a HTTPS or Websocket request) // Client wants to create a secure tcp tunnel (probably its a HTTPS or Websocket request)
if (await HttpHelper.IsConnectMethod(clientStream) == 1) if (await HttpHelper.IsConnectMethod(clientStream) == 1)
{ {
...@@ -142,15 +141,22 @@ namespace Titanium.Web.Proxy ...@@ -142,15 +141,22 @@ namespace Titanium.Web.Proxy
if (alpn != null && alpn.Contains(SslApplicationProtocol.Http2)) if (alpn != null && alpn.Contains(SslApplicationProtocol.Http2))
{ {
// test server HTTP/2 support // test server HTTP/2 support
// todo: this is a hack, because Titanium does not support HTTP protocol changing currently try
var connection = await tcpConnectionFactory.GetServerConnection(this, connectArgs, {
isConnect: true, applicationProtocols: SslExtensions.Http2ProtocolAsList, // todo: this is a hack, because Titanium does not support HTTP protocol changing currently
noCache: true, cancellationToken: cancellationToken); var connection = await tcpConnectionFactory.GetServerConnection(this, connectArgs,
isConnect: true, applicationProtocols: SslExtensions.Http2ProtocolAsList,
http2Supported = connection.NegotiatedApplicationProtocol == SslApplicationProtocol.Http2; noCache: true, cancellationToken: cancellationToken);
//release connection back to pool instead of closing when connection pool is enabled. http2Supported = connection.NegotiatedApplicationProtocol ==
await tcpConnectionFactory.Release(connection, true); SslApplicationProtocol.Http2;
//release connection back to pool instead of closing when connection pool is enabled.
await tcpConnectionFactory.Release(connection, true);
}
catch (Exception ex)
{
// ignore
}
} }
if (EnableTcpServerConnectionPrefetch) if (EnableTcpServerConnectionPrefetch)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment