diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2008-09-10 22:18:15 -0700 |
---|---|---|
committer | Andrew <andrewarnott@gmail.com> | 2008-09-10 22:18:15 -0700 |
commit | f6d28fb14c91c97f6cc8b85c442987082997866a (patch) | |
tree | c517bf2a41709319255b5b5312f3fc56c06bff6e /src/DotNetOAuth/StandardWebRequestHandler.cs | |
parent | d33318e787968182f95c183d1891c9a7d59a3b69 (diff) | |
download | DotNetOpenAuth-f6d28fb14c91c97f6cc8b85c442987082997866a.zip DotNetOpenAuth-f6d28fb14c91c97f6cc8b85c442987082997866a.tar.gz DotNetOpenAuth-f6d28fb14c91c97f6cc8b85c442987082997866a.tar.bz2 |
Code coverage work is as complete as our implementation will currently allow.
Diffstat (limited to 'src/DotNetOAuth/StandardWebRequestHandler.cs')
-rw-r--r-- | src/DotNetOAuth/StandardWebRequestHandler.cs | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/DotNetOAuth/StandardWebRequestHandler.cs b/src/DotNetOAuth/StandardWebRequestHandler.cs new file mode 100644 index 0000000..715da72 --- /dev/null +++ b/src/DotNetOAuth/StandardWebRequestHandler.cs @@ -0,0 +1,59 @@ +//-----------------------------------------------------------------------
+// <copyright file="StandardWebRequestHandler.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOAuth {
+ 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 an <see cref="HttpWebRequest"/> that contains an POST entity for sending the entity.
+ /// </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
+ }
+}
|