Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pr-v3 #13

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed ClrHttpRequest/ClrHttpRequest.jfm
Binary file not shown.
3 changes: 2 additions & 1 deletion ClrHttpRequest/ClrHttpRequest.sqlproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<ModelCollation>1033, CI</ModelCollation>
<DefaultFileStructure>BySchemaAndSchemaType</DefaultFileStructure>
<DeployToDatabase>True</DeployToDatabase>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<TargetLanguage>CS</TargetLanguage>
<AppDesignerFolder>Properties</AppDesignerFolder>
<SqlServerVerification>False</SqlServerVerification>
Expand All @@ -33,6 +33,7 @@
<Recovery>SIMPLE</Recovery>
<DacVersion>3.0.0.0</DacVersion>
<PageVerify>CHECKSUM</PageVerify>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<OutputPath>bin\Release\</OutputPath>
Expand Down
31 changes: 28 additions & 3 deletions ClrHttpRequest/clr_http_request.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,45 @@ SqlBoolean convertResponseToBas64
request.Credentials = new NetworkCredential(netCredValues[0], netCredValues[1]);
break;
case "PROXY":
var proxyValues = headerValue.Split(':');
var proxyValues = headerValue.Split(',');
if (proxyValues.Length < 2)
{
throw new FormatException("When specifying the PROXY header, please set the value in a format of URI:PORT");
throw new FormatException("When specifying the PROXY header, please set the value in a format of URI,PORT (you can also specify credentials using the format URI,PORT,username:password)");
}
int proxyPort;
if (!int.TryParse(proxyValues[1], out proxyPort))
{
throw new FormatException("When specifying the PROXY header in the format of URI:PORT, the PORT must be numeric");
throw new FormatException("When specifying the PROXY header in the format of URI,PORT the PORT must be numeric");
}
WebProxy myproxy = new WebProxy(proxyValues[0], proxyPort);
myproxy.BypassProxyOnLocal = false;

if (proxyValues.Length > 2)
{
var proxyCred = proxyValues[2].Split(':');
if (proxyCred.Length < 2)
{
throw new FormatException("When specifying the PROXY header, please set the value in a format of URI,PORT (you can also specify credentials using the format URI,PORT,username:password)");
}
else
{
var proxyCredPassword = proxyCred[1];

// if the password contains colon characters, re-stich them back into the password
for (int i = 2; i < proxyCred.Length - 1; i++)
{
proxyCredPassword += ":" + proxyCred[i];
}

myproxy.Credentials = new NetworkCredential(proxyCred[0], proxyCredPassword);
}
}

request.Proxy = myproxy;
break;
case "TrustServerCertificate":
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
break;
default: // other headers
request.Headers.Add(headerName, headerValue);
break;
Expand Down
31 changes: 27 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ My version extends the project by adding the following:
* Two new authentication methods:
* Authorization-Basic-Credentials (Basic authorization using Base64 credentials)
* Authorization-Network-Credentials (creates a new `NetworkCredential` object and assigns it to the `Credentials` property of the request)
* Added support for using a `Proxy` with a new "Proxy" header in the form of `URI:PORT`. For example: `<Header Name="Proxy">https://acmeproxy:4321</Header>`
* Added support for using a `Proxy` with a new "Proxy" header in the form of `URI,PORT[,username:password]` (credentials are optional). For example: `<Header Name="Proxy">https://acmeproxy,4321</Header>`
* Addition of a proper PreDeployment script which takes care of CLR assembly signing without requiring the TRUSTWORTHY database setting.
* Added UTF8 encoding support instead of ASCII.
* Added support for case-insensitive headers.
* Added support for TrustServerCertificate header. For example: `<Header Name="TrustServerCertificate">True</Header>`

The following code was added in clr_http_request.cs, line 19:
```cs
Expand All @@ -39,18 +40,40 @@ The following code was added in line 79 to add support for special headers:
request.Credentials = new NetworkCredential(netCredValues[0], netCredValues[1]);
break;
case "Proxy":
var proxyValues = headerValue.Split(':');
var proxyValues = headerValue.Split(',');
if (proxyValues.Length < 2)
{
throw new FormatException("When specifying the PROXY header, please set the value in a format of URI:PORT");
throw new FormatException("When specifying the PROXY header, please set the value in a format of URI,PORT (you can also specify credentials using the format URI,PORT,username:password)");
}
int proxyPort;
if (!int.TryParse(proxyValues[1], out proxyPort))
{
throw new FormatException("When specifying the PROXY header in the format of URI:PORT, the PORT must be numeric");
throw new FormatException("When specifying the PROXY header in the format of URI,PORT the PORT must be numeric");
}
WebProxy myproxy = new WebProxy(proxyValues[0], proxyPort);
myproxy.BypassProxyOnLocal = false;

if (proxyValues.Length > 2)
{
var proxyCred = proxyValues[2].Split(':');
if (proxyCred.Length < 2)
{
throw new FormatException("When specifying the PROXY header, please set the value in a format of URI,PORT (you can also specify credentials using the format URI,PORT,username:password)");
}
else
{
var proxyCredPassword = proxyCred[1];

// if the password contains colon characters, re-stich them back into the password
for (int i = 2; i < proxyCred.Length - 1; i++)
{
proxyCredPassword += ":" + proxyCred[i];
}

myproxy.Credentials = new NetworkCredential(proxyCred[0], proxyCredPassword);
}
}

request.Proxy = myproxy;
break;
```
Expand Down