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
c7faefaf
Commit
c7faefaf
authored
Mar 21, 2016
by
justcoding121
Committed by
justcoding121
Mar 21, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
issue 45
parent
da485573
Show 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 @
c7faefaf
...
@@ -384,10 +384,8 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -384,10 +384,8 @@ namespace Titanium.Web.Proxy.EventArguments
/// Before request is made to server
/// Before request is made to server
/// Respond with the specified HTML string to client
/// Respond with the specified HTML string to client
/// and ignore the request
/// and ignore the request
/// Marking as obsolete, need to comeup with a generic responder method in future
/// </summary>
/// </summary>
/// <param name="html"></param>
/// <param name="html"></param>
// [Obsolete]
public
void
Ok
(
string
html
)
public
void
Ok
(
string
html
)
{
{
if
(
ProxySession
.
Request
.
RequestLocked
)
throw
new
Exception
(
"You cannot call this function after request is made to server."
);
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
...
@@ -397,22 +395,45 @@ namespace Titanium.Web.Proxy.EventArguments
var
result
=
Encoding
.
Default
.
GetBytes
(
html
);
var
result
=
Encoding
.
Default
.
GetBytes
(
html
);
var
connectStreamWriter
=
new
StreamWriter
(
this
.
Client
.
ClientStream
);
Ok
(
result
);
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"
);
//connectStreamWriter.WriteLine(ProxySession.Request.IsAlive ? "Connection: Keep-Alive" : "Connection: close");
/// <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
();
connectStreamWriter
.
WriteLine
();
response
.
HttpVersion
=
ProxySession
.
Request
.
HttpVersion
;
connectStreamWriter
.
Flush
();
response
.
ResponseStatusCode
=
"200"
;
response
.
ResponseStatusDescription
=
"Ok"
;
this
.
Client
.
ClientStream
.
Write
(
result
,
0
,
result
.
Length
);
response
.
ResponseHeaders
.
Add
(
new
HttpHeader
(
"Timestamp"
,
DateTime
.
Now
.
ToString
()));
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"
));
ProxySession
.
Request
.
RequestLocked
=
true
;
response
.
ResponseBody
=
result
;
response
.
ResponseLocked
=
true
;
response
.
ResponseBodyRead
=
true
;
Respond
(
response
);
ProxySession
.
Request
.
CancelRequest
=
true
;
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 @
c7faefaf
...
@@ -312,6 +312,9 @@ namespace Titanium.Web.Proxy.Network
...
@@ -312,6 +312,9 @@ namespace Titanium.Web.Proxy.Network
public
void
ReceiveResponse
()
public
void
ReceiveResponse
()
{
{
//return if this is already read
if
(
this
.
Response
.
ResponseStatusCode
!=
null
)
return
;
var
httpResult
=
ProxyClient
.
ServerStreamReader
.
ReadLine
().
Split
(
new
char
[]
{
' '
},
3
);
var
httpResult
=
ProxyClient
.
ServerStreamReader
.
ReadLine
().
Split
(
new
char
[]
{
' '
},
3
);
if
(
string
.
IsNullOrEmpty
(
httpResult
[
0
]))
if
(
string
.
IsNullOrEmpty
(
httpResult
[
0
]))
...
...
Titanium.Web.Proxy/ResponseHandler.cs
View file @
c7faefaf
...
@@ -18,17 +18,17 @@ namespace Titanium.Web.Proxy
...
@@ -18,17 +18,17 @@ namespace Titanium.Web.Proxy
partial
class
ProxyServer
partial
class
ProxyServer
{
{
//Called asynchronously when a request was successfully and we received the response
//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
();
args
.
ProxySession
.
ReceiveResponse
();
try
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
);
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