diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2008-09-21 21:38:41 -0700 |
---|---|---|
committer | Andrew <andrewarnott@gmail.com> | 2008-09-21 21:38:41 -0700 |
commit | f80ac82be5e9432806ce35b7025b007246d74147 (patch) | |
tree | 9e194bfa753d03ea4deb2a02ffcd7f7db35cad0d /src/DotNetOAuth/ChannelElements/StandardWebRequestHandler.cs | |
parent | 2c381fbe2d2598e9549f5646d7bac40e49803760 (diff) | |
download | DotNetOpenAuth-f80ac82be5e9432806ce35b7025b007246d74147.zip DotNetOpenAuth-f80ac82be5e9432806ce35b7025b007246d74147.tar.gz DotNetOpenAuth-f80ac82be5e9432806ce35b7025b007246d74147.tar.bz2 |
Adding the binding elements necessary for basic OAuth functionality.
Diffstat (limited to 'src/DotNetOAuth/ChannelElements/StandardWebRequestHandler.cs')
-rw-r--r-- | src/DotNetOAuth/ChannelElements/StandardWebRequestHandler.cs | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/DotNetOAuth/ChannelElements/StandardWebRequestHandler.cs b/src/DotNetOAuth/ChannelElements/StandardWebRequestHandler.cs new file mode 100644 index 0000000..8d0adb2 --- /dev/null +++ b/src/DotNetOAuth/ChannelElements/StandardWebRequestHandler.cs @@ -0,0 +1,60 @@ +//-----------------------------------------------------------------------
+// <copyright file="StandardWebRequestHandler.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOAuth.ChannelElements {
+ using System;
+ using System.IO;
+ using System.Net;
+ using DotNetOAuth.Messaging;
+
+ /// <summary>
+ /// The default handler for transmitting <see cref="HttpWebRequest"/> instances
+ /// and returning the responses.
+ /// </summary>
+ internal class StandardWebRequestHandler : IWebRequestHandler {
+ #region IWebRequestHandler Members
+
+ /// <summary>
+ /// Prepares a POST <see cref="HttpWebRequest"/> and returns the request stream
+ /// for writing out the POST entity data.
+ /// </summary>
+ /// <param name="request">The <see cref="HttpWebRequest"/> that should contain the entity.</param>
+ /// <returns>The stream the caller should write out the entity data to.</returns>
+ public TextWriter GetRequestStream(HttpWebRequest request) {
+ if (request == null) {
+ throw new ArgumentNullException("request");
+ }
+
+ try {
+ return new StreamWriter(request.GetRequestStream());
+ } catch (WebException ex) {
+ throw new ProtocolException(MessagingStrings.ErrorInRequestReplyMessage, ex);
+ }
+ }
+
+ /// <summary>
+ /// Processes an <see cref="HttpWebRequest"/> and converts the
+ /// <see cref="HttpWebResponse"/> to a <see cref="Response"/> instance.
+ /// </summary>
+ /// <param name="request">The <see cref="HttpWebRequest"/> to handle.</param>
+ /// <returns>An instance of <see cref="Response"/> describing the response.</returns>
+ public Response GetResponse(HttpWebRequest request) {
+ if (request == null) {
+ throw new ArgumentNullException("request");
+ }
+
+ try {
+ using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) {
+ return new Response(response);
+ }
+ } catch (WebException ex) {
+ throw new ProtocolException(MessagingStrings.ErrorInRequestReplyMessage, ex);
+ }
+ }
+
+ #endregion
+ }
+}
|