HttpWebRequest CreateRequest(ITransportHeaders requestHeaders) { string url = this.url; //FIXME: requestUri should contain the URL-less URI only when it's a CAO call; // at all other times it should be null. On Mono, whenever it should be null, it contains the full // URL+URI, so we have a broken mixure of path types and we need to hack around it string requestUri = requestHeaders[CommonTransportKeys.RequestUri] as string; string objectURI; if (requestUri != null && HttpChannel.ParseInternal(requestUri, out objectURI) == null) { url = HttpChannel.ParseInternal(url, out objectURI); if (!url.EndsWith("/")) { url = url + "/"; } url = url + requestUri; } HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.UserAgent = string.Format("Mozilla/4.0+(compatible; Mono Remoting; Mono {0})", System.Environment.Version); //Only set these if they deviate from the defaults, as some map to //properties that throw NotImplementedExceptions if (channel.Timeout != -1) { request.Timeout = channel.Timeout; } if (channel.AllowAutoRedirect == false) { request.AllowAutoRedirect = false; } if (channel.Credentials != null) { request.Credentials = channel.Credentials; } #if NET_2_0 else if (channel.UseDefaultCredentials == true) { request.UseDefaultCredentials = true; } #endif else if (channel.Username != null && channel.Username.Length > 0) { if (channel.Domain != null && channel.Domain.Length > 0) { request.Credentials = new NetworkCredential(channel.Username, channel.Password, channel.Domain); } else { request.Credentials = new NetworkCredential(channel.Username, channel.Password); } } if (channel.UnsafeAuthenticatedConnectionSharing == true) { request.UnsafeAuthenticatedConnectionSharing = true; } if (channel.ConnectionGroupName != null) { request.ConnectionGroupName = channel.ConnectionGroupName; } /* * FIXME: implement these * MachineName * ProxyName * ProxyPort * ProxyUri * ServicePrincipalName * UseAuthenticatedConnectionSharing */ //build the headers request.ContentType = (string)requestHeaders["Content-Type"]; //BUG: Mono formatters/dispatcher don't set this. Something in the MS stack does. string method = (string)requestHeaders["__RequestVerb"]; if (method == null) { method = "POST"; } request.Method = method; foreach (DictionaryEntry entry in requestHeaders) { string key = entry.Key.ToString(); if (key != "__RequestVerb" && key != "Content-Type" && key != CommonTransportKeys.RequestUri) { request.Headers.Add(key, entry.Value.ToString()); } } return(request); }
public string Parse(string url, out string objectURI) { return(HttpChannel.ParseInternal(url, out objectURI)); }