//-----------------------------------------------------------------------
//
// Copyright (c) Andrew Arnott. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOAuth {
using System;
using System.IO;
using System.Net;
using DotNetOAuth.Messaging;
///
/// The default handler for transmitting instances
/// and returning the responses.
///
internal class StandardWebRequestHandler : IWebRequestHandler {
#region IWebRequestHandler Members
///
/// Prepares an that contains an POST entity for sending the entity.
///
/// The that should contain the entity.
/// The stream the caller should write out the entity data to.
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);
}
}
///
/// Processes an and converts the
/// to a instance.
///
/// The to handle.
/// An instance of describing the response.
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
}
}