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
0c88f3f1
Commit
0c88f3f1
authored
Apr 28, 2019
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
HTTP/2 fix, pushpromise commented out (not wokring yet)
parent
8bbfa308
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
78 additions
and
67 deletions
+78
-67
MainWindow.xaml.cs
examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs
+11
-6
Http2FrameHeader.cs
src/Titanium.Web.Proxy/Http2/Http2FrameHeader.cs
+6
-1
Http2Helper.cs
src/Titanium.Web.Proxy/Http2/Http2Helper.cs
+61
-60
No files found.
examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs
View file @
0c88f3f1
...
@@ -152,6 +152,11 @@ namespace Titanium.Web.Proxy.Examples.Wpf
...
@@ -152,6 +152,11 @@ namespace Titanium.Web.Proxy.Examples.Wpf
private
async
Task
ProxyServer_BeforeRequest
(
object
sender
,
SessionEventArgs
e
)
private
async
Task
ProxyServer_BeforeRequest
(
object
sender
,
SessionEventArgs
e
)
{
{
if
(
e
.
HttpClient
.
ConnectRequest
?.
TunnelType
!=
TunnelType
.
Http2
)
{
return
;
}
SessionListItem
item
=
null
;
SessionListItem
item
=
null
;
await
Dispatcher
.
InvokeAsync
(()
=>
{
item
=
addSession
(
e
);
});
await
Dispatcher
.
InvokeAsync
(()
=>
{
item
=
addSession
(
e
);
});
...
@@ -171,6 +176,11 @@ namespace Titanium.Web.Proxy.Examples.Wpf
...
@@ -171,6 +176,11 @@ namespace Titanium.Web.Proxy.Examples.Wpf
private
async
Task
ProxyServer_BeforeResponse
(
object
sender
,
SessionEventArgs
e
)
private
async
Task
ProxyServer_BeforeResponse
(
object
sender
,
SessionEventArgs
e
)
{
{
if
(
e
.
HttpClient
.
ConnectRequest
?.
TunnelType
!=
TunnelType
.
Http2
)
{
return
;
}
SessionListItem
item
=
null
;
SessionListItem
item
=
null
;
await
Dispatcher
.
InvokeAsync
(()
=>
await
Dispatcher
.
InvokeAsync
(()
=>
{
{
...
@@ -180,14 +190,9 @@ namespace Titanium.Web.Proxy.Examples.Wpf
...
@@ -180,14 +190,9 @@ namespace Titanium.Web.Proxy.Examples.Wpf
}
}
});
});
//e.SetResponseBody(Encoding.ASCII.GetBytes("TITANIUMMMM!!!!"));
//if (!e.HttpClient.Request.RequestUri.ToString().Contains("/mail/u/"))
// return;
//e.HttpClient.Response.Headers.AddHeader("X-Titanium-Header", "HTTP/2 works");
//e.HttpClient.Response.Headers.AddHeader("X-Titanium-Header", "HTTP/2 works");
//if (e.HttpClient.ConnectRequest?.TunnelType == TunnelType.Http2)
//e.SetResponseBody(Encoding.ASCII.GetBytes("TITANIUMMMM!!!!"));
//{
//}
if
(
item
!=
null
)
if
(
item
!=
null
)
{
{
...
...
src/Titanium.Web.Proxy/Http2/Http2FrameHeader.cs
View file @
0c88f3f1
...
@@ -15,12 +15,17 @@
...
@@ -15,12 +15,17 @@
public
byte
[]
CopyToBuffer
()
public
byte
[]
CopyToBuffer
()
{
{
int
length
=
Length
;
int
length
=
Length
;
var
buf
=
Buffer
;
var
buf
=
/*new byte[9];*/
Buffer
;
buf
[
0
]
=
(
byte
)((
length
>>
16
)
&
0xff
);
buf
[
0
]
=
(
byte
)((
length
>>
16
)
&
0xff
);
buf
[
1
]
=
(
byte
)((
length
>>
8
)
&
0xff
);
buf
[
1
]
=
(
byte
)((
length
>>
8
)
&
0xff
);
buf
[
2
]
=
(
byte
)(
length
&
0xff
);
buf
[
2
]
=
(
byte
)(
length
&
0xff
);
buf
[
3
]
=
(
byte
)
Type
;
buf
[
3
]
=
(
byte
)
Type
;
buf
[
4
]
=
(
byte
)
Flags
;
buf
[
4
]
=
(
byte
)
Flags
;
int
streamId
=
StreamId
;
//buf[5] = (byte)((streamId >> 24) & 0xff);
//buf[6] = (byte)((streamId >> 16) & 0xff);
//buf[7] = (byte)((streamId >> 8) & 0xff);
//buf[8] = (byte)(streamId & 0xff);
return
buf
;
return
buf
;
}
}
}
}
...
...
src/Titanium.Web.Proxy/Http2/Http2Helper.cs
View file @
0c88f3f1
...
@@ -62,7 +62,7 @@ namespace Titanium.Web.Proxy.Http2
...
@@ -62,7 +62,7 @@ namespace Titanium.Web.Proxy.Http2
int
headerTableSize
=
0
;
int
headerTableSize
=
0
;
Decoder
decoder
=
null
;
Decoder
decoder
=
null
;
Http2FrameHeade
r
frameHeader
=
new
Http2FrameHeader
();
va
r
frameHeader
=
new
Http2FrameHeader
();
frameHeader
.
Buffer
=
new
byte
[
9
];
frameHeader
.
Buffer
=
new
byte
[
9
];
byte
[]
buffer
=
null
;
byte
[]
buffer
=
null
;
while
(
true
)
while
(
true
)
...
@@ -102,20 +102,20 @@ namespace Titanium.Web.Proxy.Http2
...
@@ -102,20 +102,20 @@ namespace Titanium.Web.Proxy.Http2
bool
endStream
=
false
;
bool
endStream
=
false
;
SessionEventArgs
args
=
null
;
SessionEventArgs
args
=
null
;
RequestResponseBase
rr
;
RequestResponseBase
rr
=
null
;
if
(
type
==
Http2FrameType
.
Data
||
type
==
Http2FrameType
.
Headers
||
type
==
Http2FrameType
.
PushPromise
)
if
(
type
==
Http2FrameType
.
Data
||
type
==
Http2FrameType
.
Headers
/* || type == Http2FrameType.PushPromise*/
)
{
{
if
(!
sessions
.
TryGetValue
(
streamId
,
out
args
))
if
(!
sessions
.
TryGetValue
(
streamId
,
out
args
))
{
{
if
(
type
==
Http2FrameType
.
Data
)
//
if (type == Http2FrameType.Data)
{
//
{
throw
new
ProxyHttpException
(
"HTTP Body data received before any header frame."
,
null
,
args
);
//
throw new ProxyHttpException("HTTP Body data received before any header frame.", null, args);
}
//
}
if
(
type
==
Http2FrameType
.
Headers
&&
!
isClient
)
//
if (type == Http2FrameType.Headers && !isClient)
{
//
{
throw
new
ProxyHttpException
(
"HTTP Response received before any Request header frame."
,
null
,
args
);
//
throw new ProxyHttpException("HTTP Response received before any Request header frame.", null, args);
}
//
}
if
(
type
==
Http2FrameType
.
PushPromise
&&
isClient
)
if
(
type
==
Http2FrameType
.
PushPromise
&&
isClient
)
{
{
...
@@ -125,7 +125,7 @@ namespace Titanium.Web.Proxy.Http2
...
@@ -125,7 +125,7 @@ namespace Titanium.Web.Proxy.Http2
}
}
//System.Diagnostics.Debug.WriteLine("CONN: " + connectionId + ", CLIENT: " + isClient + ", STREAM: " + streamId + ", TYPE: " + type);
//System.Diagnostics.Debug.WriteLine("CONN: " + connectionId + ", CLIENT: " + isClient + ", STREAM: " + streamId + ", TYPE: " + type);
if
(
type
==
Http2FrameType
.
Data
)
if
(
type
==
Http2FrameType
.
Data
&&
args
!=
null
)
{
{
rr
=
isClient
?
(
RequestResponseBase
)
args
.
HttpClient
.
Request
:
args
.
HttpClient
.
Response
;
rr
=
isClient
?
(
RequestResponseBase
)
args
.
HttpClient
.
Request
:
args
.
HttpClient
.
Response
;
...
@@ -155,54 +155,6 @@ namespace Titanium.Web.Proxy.Http2
...
@@ -155,54 +155,6 @@ namespace Titanium.Web.Proxy.Http2
}
}
data
.
Write
(
buffer
,
offset
,
length
);
data
.
Write
(
buffer
,
offset
,
length
);
if
(
endStream
)
{
var
body
=
data
.
ToArray
();
if
(
rr
.
ContentEncoding
!=
null
)
{
using
(
var
ms
=
new
MemoryStream
())
{
using
(
var
zip
=
DecompressionFactory
.
Create
(
rr
.
ContentEncoding
,
new
MemoryStream
(
body
)))
{
zip
.
CopyTo
(
ms
);
}
body
=
ms
.
ToArray
();
}
}
if
(!
rr
.
BodyAvailable
)
{
rr
.
Body
=
body
;
}
rr
.
IsBodyRead
=
true
;
var
tcs
=
rr
.
ReadHttp2BodyTaskCompletionSource
;
rr
.
ReadHttp2BodyTaskCompletionSource
=
null
;
if
(!
tcs
.
Task
.
IsCompleted
)
{
tcs
.
SetResult
(
true
);
}
rr
.
Http2BodyData
=
null
;
if
(
rr
.
Http2BeforeHandlerTask
!=
null
)
{
await
rr
.
Http2BeforeHandlerTask
;
}
if
(
args
.
IsPromise
)
{
breakpoint
();
}
await
sendBody
(
remoteSettings
,
rr
,
frameHeader
,
buffer
,
output
);
}
}
}
}
}
else
if
(
type
==
Http2FrameType
.
Headers
/* || type == Http2FrameType.PushPromise*/
)
else
if
(
type
==
Http2FrameType
.
Headers
/* || type == Http2FrameType.PushPromise*/
)
...
@@ -391,6 +343,55 @@ namespace Titanium.Web.Proxy.Http2
...
@@ -391,6 +343,55 @@ namespace Titanium.Web.Proxy.Http2
}
}
}
}
if
(
endStream
&&
rr
.
ReadHttp2BodyTaskCompletionSource
!=
null
)
{
if
(!
rr
.
BodyAvailable
)
{
var
data
=
rr
.
Http2BodyData
;
var
body
=
data
.
ToArray
();
if
(
rr
.
ContentEncoding
!=
null
)
{
using
(
var
ms
=
new
MemoryStream
())
{
using
(
var
zip
=
DecompressionFactory
.
Create
(
rr
.
ContentEncoding
,
new
MemoryStream
(
body
)))
{
zip
.
CopyTo
(
ms
);
}
body
=
ms
.
ToArray
();
}
}
rr
.
Body
=
body
;
}
rr
.
IsBodyRead
=
true
;
var
tcs
=
rr
.
ReadHttp2BodyTaskCompletionSource
;
rr
.
ReadHttp2BodyTaskCompletionSource
=
null
;
if
(!
tcs
.
Task
.
IsCompleted
)
{
tcs
.
SetResult
(
true
);
}
rr
.
Http2BodyData
=
null
;
if
(
rr
.
Http2BeforeHandlerTask
!=
null
)
{
await
rr
.
Http2BeforeHandlerTask
;
}
if
(
args
.
IsPromise
)
{
breakpoint
();
}
await
sendBody
(
remoteSettings
,
rr
,
frameHeader
,
buffer
,
output
);
}
if
(!
isClient
&&
endStream
)
if
(!
isClient
&&
endStream
)
{
{
sessions
.
TryRemove
(
streamId
,
out
_
);
sessions
.
TryRemove
(
streamId
,
out
_
);
...
...
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