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
8ec26f45
Commit
8ec26f45
authored
Dec 11, 2016
by
Jehonathan
Committed by
GitHub
Dec 11, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #165 from kevinrmcd/patch-1
Adding generic response creation
parents
e2d0bf08
0555aafb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
104 additions
and
2 deletions
+104
-2
SessionEventArgs.cs
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
+82
-2
GenericResponse.cs
Titanium.Web.Proxy/Http/Responses/GenericResponse.cs
+22
-0
No files found.
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
View file @
8ec26f45
...
...
@@ -405,7 +405,8 @@ namespace Titanium.Web.Proxy.EventArguments
/// <param name="headers"></param>
public
async
Task
Ok
(
byte
[]
result
,
Dictionary
<
string
,
HttpHeader
>
headers
)
{
var
response
=
new
OkResponse
();
var
response
=
new
OkResponse
();
if
(
headers
!=
null
&&
headers
.
Count
>
0
)
{
response
.
ResponseHeaders
=
headers
;
...
...
@@ -417,7 +418,86 @@ namespace Titanium.Web.Proxy.EventArguments
WebSession
.
Request
.
CancelRequest
=
true
;
}
/// <summary>
/// Before request is made to server
/// Respond with the specified HTML string to client
/// and ignore the request
/// </summary>
/// <param name="html"></param>
/// <param name="status"></param>
public
async
Task
GenericResponse
(
string
html
,
HttpStatusCode
status
)
{
await
GenericResponse
(
html
,
null
,
status
);
}
/// <summary>
/// Before request is made to server
/// Respond with the specified HTML string to client
/// and the specified status
/// and ignore the request
/// </summary>
/// <param name="html"></param>
/// <param name="headers"></param>
/// <param name="status"></param>
public
async
Task
GenericResponse
(
string
html
,
Dictionary
<
string
,
HttpHeader
>
headers
,
HttpStatusCode
status
)
{
if
(
WebSession
.
Request
.
RequestLocked
)
{
throw
new
Exception
(
"You cannot call this function after request is made to server."
);
}
if
(
html
==
null
)
{
html
=
string
.
Empty
;
}
var
result
=
Encoding
.
Default
.
GetBytes
(
html
);
await
GenericResponse
(
result
,
headers
,
status
);
}
/// <summary>
/// Before request is made to server
/// Respond with the specified HTML string to client
/// and ignore the request
/// </summary>
/// <param name="html"></param>
/// <param name="status"></param>
/// <returns></returns>
public
async
Task
GenericResponse
(
string
html
,
HttpStatusCode
status
)
{
await
GenericResponse
(
html
,
null
,
status
);
}
/// <summary>
/// Before request is made to server
/// Respond with the specified byte[] to client
/// and the specified status
/// and ignore the request
/// </summary>
/// <param name="result"></param>
/// <param name="headers"></param>
/// <param name="status"></param>
/// <returns></returns>
public
async
Task
GenericResponse
(
byte
[]
result
,
Dictionary
<
string
,
HttpHeader
>
headers
,
HttpStatusCode
status
)
{
var
response
=
new
GenericResponse
(
status
);
if
(
headers
!=
null
&&
headers
.
Count
>
0
)
{
response
.
ResponseHeaders
=
headers
;
}
response
.
HttpVersion
=
WebSession
.
Request
.
HttpVersion
;
response
.
ResponseBody
=
result
;
await
Respond
(
response
);
WebSession
.
Request
.
CancelRequest
=
true
;
}
public
async
Task
Redirect
(
string
url
)
{
var
response
=
new
RedirectResponse
();
...
...
@@ -452,4 +532,4 @@ namespace Titanium.Web.Proxy.EventArguments
}
}
}
\ No newline at end of file
}
Titanium.Web.Proxy/Http/Responses/GenericResponse.cs
0 → 100644
View file @
8ec26f45
using
System.Net
;
namespace
Titanium.Web.Proxy.Http.Responses
{
/// <summary>
/// Anything other than a 200 or 302 response
/// </summary>
public
class
GenericResponse
:
Response
{
public
GenericResponse
(
HttpStatusCode
status
)
{
ResponseStatusCode
=
((
int
)
status
).
ToString
();
ResponseStatusDescription
=
status
.
ToString
();
}
public
GenericResponse
(
string
statusCode
,
string
statusDescription
)
{
ResponseStatusCode
=
statusCode
;
ResponseStatusDescription
=
statusCode
;
}
}
}
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