Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Titanium-Web-Proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Titanium-Web-Proxy
Commits
0e5b0299
Commit
0e5b0299
authored
Jun 25, 2017
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upgrade to Websocket fix
parent
0dd28233
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
35 deletions
+37
-35
MainWindow.xaml.cs
Examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs
+4
-0
Tcp.cs
Titanium.Web.Proxy/Helpers/Tcp.cs
+1
-33
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+32
-2
No files found.
Examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs
View file @
0e5b0299
...
@@ -81,6 +81,10 @@ namespace Titanium.Web.Proxy.Examples.Wpf
...
@@ -81,6 +81,10 @@ namespace Titanium.Web.Proxy.Examples.Wpf
SessionListItem
item
;
SessionListItem
item
;
if
(
sessionDictionary
.
TryGetValue
(
e
,
out
item
))
if
(
sessionDictionary
.
TryGetValue
(
e
,
out
item
))
{
{
item
.
Response
.
ResponseStatusCode
=
e
.
WebSession
.
Response
.
ResponseStatusCode
;
item
.
Response
.
ResponseStatusDescription
=
e
.
WebSession
.
Response
.
ResponseStatusDescription
;
item
.
Response
.
HttpVersion
=
e
.
WebSession
.
Response
.
HttpVersion
;
item
.
Response
.
ResponseHeaders
.
AddHeaders
(
e
.
WebSession
.
Response
.
ResponseHeaders
);
item
.
Update
();
item
.
Update
();
}
}
});
});
...
...
Titanium.Web.Proxy/Helpers/Tcp.cs
View file @
0e5b0299
...
@@ -6,9 +6,7 @@ using System.Runtime.InteropServices;
...
@@ -6,9 +6,7 @@ using System.Runtime.InteropServices;
using
System.Text
;
using
System.Text
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
Titanium.Web.Proxy.Extensions
;
using
Titanium.Web.Proxy.Extensions
;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Network.Tcp
;
using
Titanium.Web.Proxy.Network.Tcp
;
using
Titanium.Web.Proxy.Shared
;
namespace
Titanium.Web.Proxy.Helpers
namespace
Titanium.Web.Proxy.Helpers
{
{
...
@@ -115,43 +113,13 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -115,43 +113,13 @@ namespace Titanium.Web.Proxy.Helpers
/// relays the input clientStream to the server at the specified host name and port with the given httpCmd and headers as prefix
/// relays the input clientStream to the server at the specified host name and port with the given httpCmd and headers as prefix
/// Usefull for websocket requests
/// Usefull for websocket requests
/// </summary>
/// </summary>
/// <param name="httpCmd"></param>
/// <param name="requestHeaders"></param>
/// <param name="clientStream"></param>
/// <param name="clientStream"></param>
/// <param name="connection"></param>
/// <param name="connection"></param>
/// <param name="onDataSend"></param>
/// <param name="onDataSend"></param>
/// <param name="onDataReceive"></param>
/// <param name="onDataReceive"></param>
/// <returns></returns>
/// <returns></returns>
internal
static
async
Task
SendRaw
(
string
httpCmd
,
IEnumerable
<
HttpHeader
>
requestHeaders
,
Stream
clientStream
,
TcpConnection
connection
,
Action
<
byte
[],
int
,
int
>
onDataSend
,
Action
<
byte
[],
int
,
int
>
onDataReceive
)
internal
static
async
Task
SendRaw
(
Stream
clientStream
,
TcpConnection
connection
,
Action
<
byte
[],
int
,
int
>
onDataSend
,
Action
<
byte
[],
int
,
int
>
onDataReceive
)
{
{
//prepare the prefix content
if
(
httpCmd
!=
null
||
requestHeaders
!=
null
)
{
using
(
var
ms
=
new
MemoryStream
())
using
(
var
writer
=
new
StreamWriter
(
ms
,
Encoding
.
ASCII
)
{
NewLine
=
ProxyConstants
.
NewLine
})
{
if
(
httpCmd
!=
null
)
{
writer
.
WriteLine
(
httpCmd
);
}
if
(
requestHeaders
!=
null
)
{
foreach
(
string
header
in
requestHeaders
.
Select
(
t
=>
t
.
ToString
()))
{
writer
.
WriteLine
(
header
);
}
}
writer
.
WriteLine
();
writer
.
Flush
();
var
data
=
ms
.
ToArray
();
await
clientStream
.
WriteAsync
(
data
,
0
,
data
.
Length
);
onDataSend
?.
Invoke
(
data
,
0
,
data
.
Length
);
}
}
var
tunnelStream
=
connection
.
Stream
;
var
tunnelStream
=
connection
.
Stream
;
//Now async relay all server=>client & client=>server data
//Now async relay all server=>client & client=>server data
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
0e5b0299
...
@@ -6,6 +6,7 @@ using System.Net;
...
@@ -6,6 +6,7 @@ using System.Net;
using
System.Net.Security
;
using
System.Net.Security
;
using
System.Net.Sockets
;
using
System.Net.Sockets
;
using
System.Security.Authentication
;
using
System.Security.Authentication
;
using
System.Text
;
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
Titanium.Web.Proxy.EventArguments
;
using
Titanium.Web.Proxy.EventArguments
;
...
@@ -178,7 +179,7 @@ namespace Titanium.Web.Proxy
...
@@ -178,7 +179,7 @@ namespace Titanium.Web.Proxy
//create new connection
//create new connection
using
(
var
connection
=
await
GetServerConnection
(
connectArgs
))
using
(
var
connection
=
await
GetServerConnection
(
connectArgs
))
{
{
await
TcpHelper
.
SendRaw
(
null
,
null
,
clientStream
,
connection
,
await
TcpHelper
.
SendRaw
(
clientStream
,
connection
,
(
buffer
,
offset
,
count
)
=>
{
connectArgs
.
OnDataSent
(
buffer
,
offset
,
count
);
},
(
buffer
,
offset
,
count
)
=>
{
connectArgs
.
OnDataReceived
(
buffer
,
offset
,
count
);
});
(
buffer
,
offset
,
count
)
=>
{
connectArgs
.
OnDataSent
(
buffer
,
offset
,
count
);
},
(
buffer
,
offset
,
count
)
=>
{
connectArgs
.
OnDataReceived
(
buffer
,
offset
,
count
);
});
Interlocked
.
Decrement
(
ref
serverConnectionCount
);
Interlocked
.
Decrement
(
ref
serverConnectionCount
);
}
}
...
@@ -375,7 +376,36 @@ namespace Titanium.Web.Proxy
...
@@ -375,7 +376,36 @@ namespace Titanium.Web.Proxy
//if upgrading to websocket then relay the requet without reading the contents
//if upgrading to websocket then relay the requet without reading the contents
if
(
args
.
WebSession
.
Request
.
UpgradeToWebSocket
)
if
(
args
.
WebSession
.
Request
.
UpgradeToWebSocket
)
{
{
await
TcpHelper
.
SendRaw
(
httpCmd
,
args
.
WebSession
.
Request
.
RequestHeaders
,
clientStream
,
connection
,
//prepare the prefix content
var
requestHeaders
=
args
.
WebSession
.
Request
.
RequestHeaders
;
using
(
var
ms
=
new
MemoryStream
())
using
(
var
writer
=
new
StreamWriter
(
ms
,
Encoding
.
ASCII
)
{
NewLine
=
ProxyConstants
.
NewLine
})
{
writer
.
WriteLine
(
httpCmd
);
if
(
requestHeaders
!=
null
)
{
foreach
(
string
header
in
requestHeaders
.
Select
(
t
=>
t
.
ToString
()))
{
writer
.
WriteLine
(
header
);
}
}
writer
.
WriteLine
();
writer
.
Flush
();
var
data
=
ms
.
ToArray
();
await
connection
.
Stream
.
WriteAsync
(
data
,
0
,
data
.
Length
);
}
string
httpStatus
=
await
connection
.
StreamReader
.
ReadLineAsync
();
//todo: parse status
await
HeaderParser
.
ReadHeaders
(
connection
.
StreamReader
,
args
.
WebSession
.
Response
.
ResponseHeaders
);
await
clientStreamWriter
.
WriteLineAsync
(
httpStatus
);
await
WriteResponseHeaders
(
clientStreamWriter
,
args
.
WebSession
.
Response
);
await
TcpHelper
.
SendRaw
(
clientStream
,
connection
,
(
buffer
,
offset
,
count
)
=>
{
args
.
OnDataSent
(
buffer
,
offset
,
count
);
},
(
buffer
,
offset
,
count
)
=>
{
args
.
OnDataReceived
(
buffer
,
offset
,
count
);
});
(
buffer
,
offset
,
count
)
=>
{
args
.
OnDataSent
(
buffer
,
offset
,
count
);
},
(
buffer
,
offset
,
count
)
=>
{
args
.
OnDataReceived
(
buffer
,
offset
,
count
);
});
args
.
Dispose
();
args
.
Dispose
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment