summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2010-02-02 06:55:56 -0800
committerAndrew Arnott <andrewarnott@gmail.com>2010-02-02 06:55:56 -0800
commitda0c7f700cdf1dc00929f1597e263ca9b4977826 (patch)
tree0e161194d0a38e462a2a5ef3b68aedc35d074dfe /src
parentdfa6d41368c85195fe2603eab4e3d6e7f2b7de9f (diff)
downloadDotNetOpenAuth-da0c7f700cdf1dc00929f1597e263ca9b4977826.zip
DotNetOpenAuth-da0c7f700cdf1dc00929f1597e263ca9b4977826.tar.gz
DotNetOpenAuth-da0c7f700cdf1dc00929f1597e263ca9b4977826.tar.bz2
Fixed parsing the Content-Type header in a couple places.
Fixed a few failing unit tests.
Diffstat (limited to 'src')
-rw-r--r--src/DotNetOpenAuth.Test/Messaging/MessagingUtilitiesTests.cs1
-rw-r--r--src/DotNetOpenAuth.Test/Messaging/OutgoingWebResponseTests.cs4
-rw-r--r--src/DotNetOpenAuth/Messaging/HttpRequestInfo.cs4
-rw-r--r--src/DotNetOpenAuth/OAuth/ChannelElements/OAuthChannel.cs10
4 files changed, 14 insertions, 5 deletions
diff --git a/src/DotNetOpenAuth.Test/Messaging/MessagingUtilitiesTests.cs b/src/DotNetOpenAuth.Test/Messaging/MessagingUtilitiesTests.cs
index 21c589f..4fc89a7 100644
--- a/src/DotNetOpenAuth.Test/Messaging/MessagingUtilitiesTests.cs
+++ b/src/DotNetOpenAuth.Test/Messaging/MessagingUtilitiesTests.cs
@@ -153,6 +153,7 @@ namespace DotNetOpenAuth.Test.Messaging
Match m = Regex.Match(req.ContentType, "multipart/form-data; boundary=(.+)");
Assert.IsTrue(m.Success, "Content-Type HTTP header not set correctly.");
string boundary = m.Groups[1].Value;
+ boundary = boundary.Substring(0, boundary.IndexOf(';')); // trim off charset
string expectedEntity = "--{0}\r\nContent-Disposition: form-data; name=\"a\"\r\n\r\nb\r\n--{0}--\r\n";
expectedEntity = string.Format(expectedEntity, boundary);
string actualEntity = httpHandler.RequestEntityAsString;
diff --git a/src/DotNetOpenAuth.Test/Messaging/OutgoingWebResponseTests.cs b/src/DotNetOpenAuth.Test/Messaging/OutgoingWebResponseTests.cs
index 35f9259..2923af4 100644
--- a/src/DotNetOpenAuth.Test/Messaging/OutgoingWebResponseTests.cs
+++ b/src/DotNetOpenAuth.Test/Messaging/OutgoingWebResponseTests.cs
@@ -6,6 +6,7 @@
namespace DotNetOpenAuth.Test.Messaging {
using System.Net;
+ using System.Net.Mime;
using System.Text;
using DotNetOpenAuth.Messaging;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -30,7 +31,8 @@ namespace DotNetOpenAuth.Test.Messaging {
CollectionAssert.AreEqual(expectedBuffer, actualBuffer);
// Verify that the header was set correctly.
- Assert.AreEqual(encoding.HeaderName, response.Headers[HttpResponseHeader.ContentEncoding]);
+ Assert.IsNull(response.Headers[HttpResponseHeader.ContentEncoding]);
+ Assert.AreEqual(encoding.HeaderName, new ContentType(response.Headers[HttpResponseHeader.ContentType]).CharSet);
}
}
}
diff --git a/src/DotNetOpenAuth/Messaging/HttpRequestInfo.cs b/src/DotNetOpenAuth/Messaging/HttpRequestInfo.cs
index 94990c8..6ce87a8 100644
--- a/src/DotNetOpenAuth/Messaging/HttpRequestInfo.cs
+++ b/src/DotNetOpenAuth/Messaging/HttpRequestInfo.cs
@@ -13,6 +13,7 @@ namespace DotNetOpenAuth.Messaging {
using System.Globalization;
using System.IO;
using System.Net;
+ using System.Net.Mime;
using System.ServiceModel.Channels;
using System.Web;
@@ -233,7 +234,8 @@ namespace DotNetOpenAuth.Messaging {
get {
Contract.Ensures(Contract.Result<NameValueCollection>() != null);
if (this.form == null) {
- if (this.HttpMethod == "POST" && this.Headers[HttpRequestHeader.ContentType] == Channel.HttpFormUrlEncoded) {
+ ContentType contentType = string.IsNullOrEmpty(this.Headers[HttpRequestHeader.ContentType]) ? null : new ContentType(this.Headers[HttpRequestHeader.ContentType]);
+ if (this.HttpMethod == "POST" && contentType != null && string.Equals(contentType.MediaType, Channel.HttpFormUrlEncoded, StringComparison.Ordinal)) {
StreamReader reader = new StreamReader(this.InputStream);
long originalPosition = 0;
if (this.InputStream.CanSeek) {
diff --git a/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthChannel.cs b/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthChannel.cs
index 499b996..1af2d7e 100644
--- a/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthChannel.cs
+++ b/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthChannel.cs
@@ -12,6 +12,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
using System.Globalization;
using System.IO;
using System.Net;
+ using System.Net.Mime;
using System.Text;
using System.Web;
using DotNetOpenAuth.Messaging;
@@ -140,9 +141,12 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
}
// Scrape the entity
- if (string.Equals(request.Headers[HttpRequestHeader.ContentType], HttpFormUrlEncoded, StringComparison.Ordinal)) {
- foreach (string key in request.Form) {
- fields.Add(key, request.Form[key]);
+ if (!string.IsNullOrEmpty(request.Headers[HttpRequestHeader.ContentType])) {
+ ContentType contentType = new ContentType(request.Headers[HttpRequestHeader.ContentType]);
+ if (string.Equals(contentType.MediaType, HttpFormUrlEncoded, StringComparison.Ordinal)) {
+ foreach (string key in request.Form) {
+ fields.Add(key, request.Form[key]);
+ }
}
}