summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2009-01-07 17:28:10 -0800
committerAndrew <andrewarnott@gmail.com>2009-01-07 17:28:10 -0800
commit09a2a95d9f7860b2d7850b4a98e7895e938e5805 (patch)
tree7d0bd7dde171665e782658463781bf38a23546b5 /src
parent5ff53d153719862d6659e7b42325582f821a3185 (diff)
downloadDotNetOpenAuth-09a2a95d9f7860b2d7850b4a98e7895e938e5805.zip
DotNetOpenAuth-09a2a95d9f7860b2d7850b4a98e7895e938e5805.tar.gz
DotNetOpenAuth-09a2a95d9f7860b2d7850b4a98e7895e938e5805.tar.bz2
Added HTTP User-Agent header.
Oddly, this header is required in order to perform discovery on technorati OpenIDs. Ported from DNOI 5725661430982334d24e89f52517e0c7907450af. See Google Code Issue 181.
Diffstat (limited to 'src')
-rw-r--r--src/DotNetOpenAuth/Messaging/StandardWebRequestHandler.cs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth/Messaging/StandardWebRequestHandler.cs b/src/DotNetOpenAuth/Messaging/StandardWebRequestHandler.cs
index 5ecd529..47a5040 100644
--- a/src/DotNetOpenAuth/Messaging/StandardWebRequestHandler.cs
+++ b/src/DotNetOpenAuth/Messaging/StandardWebRequestHandler.cs
@@ -9,6 +9,7 @@ namespace DotNetOpenAuth.Messaging {
using System.IO;
using System.Net;
using System.Net.Sockets;
+ using System.Reflection;
using DotNetOpenAuth.Messaging;
/// <summary>
@@ -16,6 +17,11 @@ namespace DotNetOpenAuth.Messaging {
/// and returning the responses.
/// </summary>
internal class StandardWebRequestHandler : IDirectWebRequestHandler {
+ /// <summary>
+ /// The value to use for the User-Agent HTTP header.
+ /// </summary>
+ private static string userAgentValue = Assembly.GetExecutingAssembly().GetName().Name + "/" + Assembly.GetExecutingAssembly().GetName().Version;
+
#region IWebRequestHandler Members
/// <summary>
@@ -84,6 +90,12 @@ namespace DotNetOpenAuth.Messaging {
/// <param name="request">The HTTP request with information about the remote party to contact.</param>
/// <returns>The stream where the POST entity can be written.</returns>
private static TextWriter GetRequestStreamCore(HttpWebRequest request) {
+ // Some sites, such as Technorati, return 403 Forbidden on identity
+ // pages unless a User-Agent header is included.
+ if (string.IsNullOrEmpty(request.UserAgent)) {
+ request.UserAgent = userAgentValue;
+ }
+
try {
return new StreamWriter(request.GetRequestStream());
} catch (SocketException ex) {