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
f0232896
Commit
f0232896
authored
May 20, 2017
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Content type fixed in request header, too (moved to a common place)
parent
203a8310
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
68 deletions
+59
-68
HttpWebRequestExtensions.cs
Titanium.Web.Proxy/Extensions/HttpWebRequestExtensions.cs
+2
-28
HttpWebResponseExtensions.cs
Titanium.Web.Proxy/Extensions/HttpWebResponseExtensions.cs
+2
-40
HeaderHelper.cs
Titanium.Web.Proxy/Helpers/HeaderHelper.cs
+54
-0
Titanium.Web.Proxy.csproj
Titanium.Web.Proxy/Titanium.Web.Proxy.csproj
+1
-0
No files found.
Titanium.Web.Proxy/Extensions/HttpWebRequestExtensions.cs
View file @
f0232896
using
System
;
using
System
;
using
System.Text
;
using
System.Text
;
using
Titanium.Web.Proxy.Helpers
;
using
Titanium.Web.Proxy.Http
;
using
Titanium.Web.Proxy.Http
;
using
Titanium.Web.Proxy.Shared
;
namespace
Titanium.Web.Proxy.Extensions
namespace
Titanium.Web.Proxy.Extensions
{
{
...
@@ -17,33 +17,7 @@ namespace Titanium.Web.Proxy.Extensions
...
@@ -17,33 +17,7 @@ namespace Titanium.Web.Proxy.Extensions
/// <returns></returns>
/// <returns></returns>
internal
static
Encoding
GetEncoding
(
this
Request
request
)
internal
static
Encoding
GetEncoding
(
this
Request
request
)
{
{
try
return
HeaderHelper
.
GetEncodingFromContentType
(
request
.
ContentType
);
{
//return default if not specified
if
(
request
.
ContentType
==
null
)
{
return
Encoding
.
GetEncoding
(
"ISO-8859-1"
);
}
//extract the encoding by finding the charset
var
contentTypes
=
request
.
ContentType
.
Split
(
ProxyConstants
.
SemiColonSplit
);
foreach
(
var
contentType
in
contentTypes
)
{
var
encodingSplit
=
contentType
.
Split
(
'='
);
if
(
encodingSplit
.
Length
==
2
&&
encodingSplit
[
0
].
Trim
().
Equals
(
"charset"
,
StringComparison
.
CurrentCultureIgnoreCase
))
{
return
Encoding
.
GetEncoding
(
encodingSplit
[
1
]);
}
}
}
catch
{
//parsing errors
// ignored
}
//return default if not specified
return
Encoding
.
GetEncoding
(
"ISO-8859-1"
);
}
}
}
}
}
}
Titanium.Web.Proxy/Extensions/HttpWebResponseExtensions.cs
View file @
f0232896
using
System
;
using
System
;
using
System.Text
;
using
System.Text
;
using
Titanium.Web.Proxy.Helpers
;
using
Titanium.Web.Proxy.Http
;
using
Titanium.Web.Proxy.Http
;
using
Titanium.Web.Proxy.Shared
;
namespace
Titanium.Web.Proxy.Extensions
namespace
Titanium.Web.Proxy.Extensions
{
{
...
@@ -14,45 +14,7 @@ namespace Titanium.Web.Proxy.Extensions
...
@@ -14,45 +14,7 @@ namespace Titanium.Web.Proxy.Extensions
/// <returns></returns>
/// <returns></returns>
internal
static
Encoding
GetResponseCharacterEncoding
(
this
Response
response
)
internal
static
Encoding
GetResponseCharacterEncoding
(
this
Response
response
)
{
{
try
return
HeaderHelper
.
GetEncodingFromContentType
(
response
.
ContentType
);
{
//return default if not specified
if
(
response
.
ContentType
==
null
)
{
return
Encoding
.
GetEncoding
(
"ISO-8859-1"
);
}
//extract the encoding by finding the charset
var
contentTypes
=
response
.
ContentType
.
Split
(
ProxyConstants
.
SemiColonSplit
);
foreach
(
var
contentType
in
contentTypes
)
{
var
encodingSplit
=
contentType
.
Split
(
ProxyConstants
.
EqualSplit
,
2
);
if
(
encodingSplit
.
Length
==
2
&&
encodingSplit
[
0
].
Trim
().
Equals
(
"charset"
,
StringComparison
.
CurrentCultureIgnoreCase
))
{
string
value
=
encodingSplit
[
1
];
if
(
value
.
Equals
(
"x-user-defined"
,
StringComparison
.
OrdinalIgnoreCase
))
{
//todo: what is this?
continue
;
}
if
(
value
.
Length
>
2
&&
value
[
0
]
==
'"'
&&
value
[
value
.
Length
-
1
]
==
'"'
)
{
value
=
value
.
Substring
(
1
,
value
.
Length
-
2
);
}
return
Encoding
.
GetEncoding
(
value
);
}
}
}
catch
{
//parsing errors
// ignored
}
//return default if not specified
return
Encoding
.
GetEncoding
(
"ISO-8859-1"
);
}
}
}
}
}
}
Titanium.Web.Proxy/Helpers/HeaderHelper.cs
0 → 100644
View file @
f0232896
using
System
;
using
System.Text
;
using
Titanium.Web.Proxy.Shared
;
namespace
Titanium.Web.Proxy.Helpers
{
internal
static
class
HeaderHelper
{
private
static
readonly
Encoding
defaultEncoding
=
Encoding
.
GetEncoding
(
"ISO-8859-1"
);
public
static
Encoding
GetEncodingFromContentType
(
string
contentType
)
{
try
{
//return default if not specified
if
(
contentType
==
null
)
{
return
defaultEncoding
;
}
//extract the encoding by finding the charset
var
parameters
=
contentType
.
Split
(
ProxyConstants
.
SemiColonSplit
);
foreach
(
var
parameter
in
parameters
)
{
var
encodingSplit
=
parameter
.
Split
(
ProxyConstants
.
EqualSplit
,
2
);
if
(
encodingSplit
.
Length
==
2
&&
encodingSplit
[
0
].
Trim
().
Equals
(
"charset"
,
StringComparison
.
CurrentCultureIgnoreCase
))
{
string
value
=
encodingSplit
[
1
];
if
(
value
.
Equals
(
"x-user-defined"
,
StringComparison
.
OrdinalIgnoreCase
))
{
//todo: what is this?
continue
;
}
if
(
value
.
Length
>
2
&&
value
[
0
]
==
'"'
&&
value
[
value
.
Length
-
1
]
==
'"'
)
{
value
=
value
.
Substring
(
1
,
value
.
Length
-
2
);
}
return
Encoding
.
GetEncoding
(
value
);
}
}
}
catch
{
//parsing errors
// ignored
}
//return default if not specified
return
defaultEncoding
;
}
}
}
Titanium.Web.Proxy/Titanium.Web.Proxy.csproj
View file @
f0232896
...
@@ -74,6 +74,7 @@
...
@@ -74,6 +74,7 @@
<Compile
Include=
"EventArguments\CertificateValidationEventArgs.cs"
/>
<Compile
Include=
"EventArguments\CertificateValidationEventArgs.cs"
/>
<Compile
Include=
"Extensions\ByteArrayExtensions.cs"
/>
<Compile
Include=
"Extensions\ByteArrayExtensions.cs"
/>
<Compile
Include=
"Extensions\FuncExtensions.cs"
/>
<Compile
Include=
"Extensions\FuncExtensions.cs"
/>
<Compile
Include=
"Helpers\HeaderHelper.cs"
/>
<Compile
Include=
"Extensions\StringExtensions.cs"
/>
<Compile
Include=
"Extensions\StringExtensions.cs"
/>
<Compile
Include=
"Helpers\BufferPool.cs"
/>
<Compile
Include=
"Helpers\BufferPool.cs"
/>
<Compile
Include=
"Helpers\CustomBufferedStream.cs"
/>
<Compile
Include=
"Helpers\CustomBufferedStream.cs"
/>
...
...
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