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
81975c47
Commit
81975c47
authored
Jun 25, 2017
by
justcoding121
Committed by
justcoding121
Jun 25, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #285 from honfika/develop
Fix for #284
parents
fb0b8b11
1093c785
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
36 deletions
+38
-36
MainWindow.xaml.cs
Examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs
+5
-1
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 @
81975c47
...
...
@@ -81,6 +81,10 @@ namespace Titanium.Web.Proxy.Examples.Wpf
SessionListItem
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
();
}
});
...
...
@@ -151,7 +155,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
item
.
Request
.
RequestHeaders
.
AddHeaders
(
e
.
WebSession
.
Request
.
RequestHeaders
);
if
(
e
is
TunnelConnectSessionEventArgs
)
if
(
e
is
TunnelConnectSessionEventArgs
||
e
.
WebSession
.
Request
.
UpgradeToWebSocket
)
{
e
.
DataReceived
+=
(
sender
,
args
)
=>
{
...
...
Titanium.Web.Proxy/Helpers/Tcp.cs
View file @
81975c47
...
...
@@ -6,9 +6,7 @@ using System.Runtime.InteropServices;
using
System.Text
;
using
System.Threading.Tasks
;
using
Titanium.Web.Proxy.Extensions
;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Network.Tcp
;
using
Titanium.Web.Proxy.Shared
;
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
/// Usefull for websocket requests
/// </summary>
/// <param name="httpCmd"></param>
/// <param name="requestHeaders"></param>
/// <param name="clientStream"></param>
/// <param name="connection"></param>
/// <param name="onDataSend"></param>
/// <param name="onDataReceive"></param>
/// <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
;
//Now async relay all server=>client & client=>server data
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
81975c47
...
...
@@ -6,6 +6,7 @@ using System.Net;
using
System.Net.Security
;
using
System.Net.Sockets
;
using
System.Security.Authentication
;
using
System.Text
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Titanium.Web.Proxy.EventArguments
;
...
...
@@ -178,7 +179,7 @@ namespace Titanium.Web.Proxy
//create new connection
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
);
});
Interlocked
.
Decrement
(
ref
serverConnectionCount
);
}
...
...
@@ -375,7 +376,36 @@ namespace Titanium.Web.Proxy
//if upgrading to websocket then relay the requet without reading the contents
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
);
});
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