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
8d7986ec
Commit
8d7986ec
authored
Mar 21, 2016
by
titanium007
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
issue 45
parent
7fd744bb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
17 deletions
+41
-17
SessionEventArgs.cs
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
+34
-13
HttpWebClient.cs
Titanium.Web.Proxy/Network/HttpWebClient.cs
+3
-0
ResponseHandler.cs
Titanium.Web.Proxy/ResponseHandler.cs
+4
-4
No files found.
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
View file @
8d7986ec
...
...
@@ -384,10 +384,8 @@ namespace Titanium.Web.Proxy.EventArguments
/// Before request is made to server
/// Respond with the specified HTML string to client
/// and ignore the request
/// Marking as obsolete, need to comeup with a generic responder method in future
/// </summary>
/// <param name="html"></param>
// [Obsolete]
public
void
Ok
(
string
html
)
{
if
(
ProxySession
.
Request
.
RequestLocked
)
throw
new
Exception
(
"You cannot call this function after request is made to server."
);
...
...
@@ -397,22 +395,45 @@ namespace Titanium.Web.Proxy.EventArguments
var
result
=
Encoding
.
Default
.
GetBytes
(
html
);
var
connectStreamWriter
=
new
StreamWriter
(
this
.
Client
.
ClientStream
);
connectStreamWriter
.
WriteLine
(
string
.
Format
(
"{0} {1} {2}"
,
ProxySession
.
Request
.
HttpVersion
,
200
,
"Ok"
));
connectStreamWriter
.
WriteLine
(
"Timestamp: {0}"
,
DateTime
.
Now
);
connectStreamWriter
.
WriteLine
(
"content-length: "
+
result
.
Length
);
connectStreamWriter
.
WriteLine
(
"Cache-Control: no-cache, no-store, must-revalidate"
);
connectStreamWriter
.
WriteLine
(
"Pragma: no-cache"
);
connectStreamWriter
.
WriteLine
(
"Expires: 0"
);
Ok
(
result
);
}
/// <summary>
/// Before request is made to server
/// Respond with the specified byte[] to client
/// and ignore the request
/// </summary>
/// <param name="body"></param>
public
void
Ok
(
byte
[]
result
)
{
var
response
=
new
Response
();
response
.
HttpVersion
=
ProxySession
.
Request
.
HttpVersion
;
response
.
ResponseStatusCode
=
"200"
;
response
.
ResponseStatusDescription
=
"Ok"
;
//connectStreamWriter.WriteLine(ProxySession.Request.IsAlive ? "Connection: Keep-Alive" : "Connection: close"
);
response
.
ResponseHeaders
.
Add
(
new
HttpHeader
(
"Timestamp"
,
DateTime
.
Now
.
ToString
())
);
connectStreamWriter
.
WriteLine
();
connectStreamWriter
.
Flush
();
response
.
ResponseHeaders
.
Add
(
new
HttpHeader
(
"content-length"
,
DateTime
.
Now
.
ToString
()));
response
.
ResponseHeaders
.
Add
(
new
HttpHeader
(
"Cache-Control"
,
"no-cache, no-store, must-revalidate"
));
response
.
ResponseHeaders
.
Add
(
new
HttpHeader
(
"Pragma"
,
"no-cache"
));
response
.
ResponseHeaders
.
Add
(
new
HttpHeader
(
"Expires"
,
"0"
));
this
.
Client
.
ClientStream
.
Write
(
result
,
0
,
result
.
Length
);
ProxySession
.
Request
.
RequestLocked
=
true
;
response
.
ResponseBody
=
result
;
response
.
ResponseLocked
=
true
;
response
.
ResponseBodyRead
=
true
;
Respond
(
response
);
ProxySession
.
Request
.
CancelRequest
=
true
;
}
/// a generic responder method
public
void
Respond
(
Response
response
)
{
ProxySession
.
Response
=
response
;
ProxyServer
.
HandleHttpSessionResponse
(
this
);
}
}
}
\ No newline at end of file
Titanium.Web.Proxy/Network/HttpWebClient.cs
View file @
8d7986ec
...
...
@@ -312,6 +312,9 @@ namespace Titanium.Web.Proxy.Network
public
void
ReceiveResponse
()
{
//return if this is already read
if
(
this
.
Response
.
ResponseStatusCode
!=
null
)
return
;
var
httpResult
=
ProxyClient
.
ServerStreamReader
.
ReadLine
().
Split
(
new
char
[]
{
' '
},
3
);
if
(
string
.
IsNullOrEmpty
(
httpResult
[
0
]))
...
...
Titanium.Web.Proxy/ResponseHandler.cs
View file @
8d7986ec
...
...
@@ -18,17 +18,17 @@ namespace Titanium.Web.Proxy
partial
class
ProxyServer
{
//Called asynchronously when a request was successfully and we received the response
p
rivate
static
void
HandleHttpSessionResponse
(
SessionEventArgs
args
)
p
ublic
static
void
HandleHttpSessionResponse
(
SessionEventArgs
args
)
{
args
.
ProxySession
.
ReceiveResponse
();
try
{
if
(!
args
.
ProxySession
.
Response
.
ResponseBodyRead
)
args
.
ProxySession
.
Response
.
ResponseStream
=
args
.
ProxySession
.
ProxyClient
.
ServerStreamReader
.
BaseStream
;
args
.
ProxySession
.
Response
.
ResponseStream
=
args
.
ProxySession
.
ProxyClient
.
ServerStreamReader
.
BaseStream
;
if
(
BeforeResponse
!=
null
)
if
(
BeforeResponse
!=
null
&&
!
args
.
ProxySession
.
Response
.
ResponseLocked
)
{
BeforeResponse
(
null
,
args
);
}
...
...
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