();
}
removed_headers.Add(hdr);
if (headers != null)
{
headers.Remove(hdr);
}
}
// Should it prove necessary, we could always
// restore the header collection from a cloned
// copy, but for now we'll assume that that is
// not necessary.
private void BuildHeaders()
{
if (removed_headers != null)
{
foreach (string h in removed_headers)
{
Rest.Log.DebugFormat("{0} Removing header: <{1}>", MsgId, h);
response.Headers.Remove(h);
}
}
if (headers!= null)
{
for (int i = 0; i < headers.Count; i++)
{
Rest.Log.DebugFormat("{0} Adding header: <{1}: {2}>",
MsgId, headers.GetKey(i), headers.Get(i));
response.Headers.Add(headers.GetKey(i), headers.Get(i));
}
}
}
///
/// Helper methods for deconstructing and reconstructing
/// URI path data.
///
private void initUrl()
{
uri = request.Url;
if (query == null)
{
query = uri.Query;
}
// If the path has not been previously initialized,
// do so now.
if (path == null)
{
path = uri.AbsolutePath;
if (path.EndsWith(Rest.UrlPathSeparator))
path = path.Substring(0,path.Length-1);
path = Uri.UnescapeDataString(path);
}
// If we succeeded in getting a path, perform any
// additional pre-processing required.
if (path != null)
{
if (Rest.ExtendedEscape)
{
// Handle "+". Not a standard substitution, but
// common enough...
path = path.Replace(Rest.C_PLUS,Rest.C_SPACE);
}
pathNodes = path.Split(Rest.CA_PATHSEP);
}
else
{
pathNodes = EmptyPath;
}
// Request server context info
hostname = uri.Host;
port = uri.Port;
}
internal int initParameters(int prfxlen)
{
if (prfxlen < path.Length-1)
{
parameters = path.Substring(prfxlen+1).Split(Rest.CA_PATHSEP);
}
else
{
parameters = new string[0];
}
// Generate a debug list of the decoded parameters
if (Rest.DEBUG && prfxlen < path.Length-1)
{
Rest.Log.DebugFormat("{0} URI: Parameters: {1}", MsgId, path.Substring(prfxlen));
for (int i = 0; i < parameters.Length; i++)
{
Rest.Log.DebugFormat("{0} Parameter[{1}]: {2}", MsgId, i, parameters[i]);
}
}
return parameters.Length;
}
internal string[] PathNodes
{
get
{
if (pathNodes == null)
{
initUrl();
}
return pathNodes;
}
}
internal string BuildUrl(int first, int last)
{
if (pathNodes == null)
{
initUrl();
}
if (first < 0)
{
first = first + pathNodes.Length;
}
if (last < 0)
{
last = last + pathNodes.Length;
if (last < 0)
{
return Rest.UrlPathSeparator;
}
}
sbuilder.Length = 0;
sbuilder.Append(Rest.UrlPathSeparator);
if (first <= last)
{
for (int i = first; i <= last; i++)
{
sbuilder.Append(pathNodes[i]);
sbuilder.Append(Rest.UrlPathSeparator);
}
}
else
{
for (int i = last; i >= first; i--)
{
sbuilder.Append(pathNodes[i]);
sbuilder.Append(Rest.UrlPathSeparator);
}
}
return sbuilder.ToString();
}
// Setup the XML writer for output
internal void initXmlWriter()
{
XmlWriterSettings settings = new XmlWriterSettings();
xmldata = new MemoryStream();
settings.Indent = true;
settings.IndentChars = " ";
settings.Encoding = encoding;
settings.CloseOutput = false;
settings.OmitXmlDeclaration = true;
settings.ConformanceLevel = ConformanceLevel.Fragment;
writer = XmlWriter.Create(xmldata, settings);
}
internal void initXmlReader()
{
XmlReaderSettings settings = new XmlReaderSettings();
settings.ConformanceLevel = ConformanceLevel.Fragment;
settings.IgnoreComments = true;
settings.IgnoreWhitespace = true;
settings.IgnoreProcessingInstructions = true;
settings.ValidationType = ValidationType.None;
// reader = XmlReader.Create(new StringReader(entity),settings);
reader = XmlReader.Create(request.InputStream,settings);
}
private void Flush()
{
byte[] dbuffer = new byte[8192];
while (request.InputStream.Read(dbuffer,0,dbuffer.Length) != 0);
return;
}
// This allows us to make errors a bit more apparent in REST
internal void SendHtml(string text)
{
SendHtml("OpenSim REST Interface 1.0", text);
}
internal void SendHtml(string title, string text)
{
AddHeader(Rest.HttpHeaderContentType, "text/html");
sbuilder.Length = 0;
sbuilder.Append("");
sbuilder.Append("");
sbuilder.Append("");
sbuilder.Append(title);
sbuilder.Append("");
sbuilder.Append("");
sbuilder.Append("");
sbuilder.Append("
");
sbuilder.Append("");
sbuilder.Append(text);
sbuilder.Append("
");
sbuilder.Append("");
sbuilder.Append("");
html = sbuilder.ToString();
}
}
}