singrdk/base/Libraries/WebApps/RemoteHttpRequest.sg

207 lines
5.8 KiB
Plaintext
Raw Normal View History

2008-03-05 09:52:00 -05:00
///////////////////////////////////////////////////////////////////////////////
//
// Microsoft Research Singularity
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// File: RemoteHttpRequest.sg
//
// Note:
// This file wraps a HttpRequestContract so it can be accessed like a
// regular object.
//
using System;
using Microsoft.SingSharp;
using Microsoft.SingSharp.Runtime;
using Microsoft.Singularity.Channels;
using Microsoft.Singularity.WebApps.Contracts;
namespace Microsoft.Singularity.WebApps
{
public class RemoteHttpRequest : IHttpRequest
{
private TRef<HttpRequestContract.Imp:Start> m_Conn;
public RemoteHttpRequest([Claims] HttpRequestContract.Imp:Start! conn)
{
m_Conn = new TRef<HttpRequestContract.Imp:Start>(conn);
}
public string! GetUriPath()
{
HttpRequestContract.Imp conn = m_Conn.Acquire();
2008-11-17 18:29:00 -05:00
try {
2008-03-05 09:52:00 -05:00
char[]! in ExHeap uriChars;
conn.SendGetUriPath();
conn.RecvUriPath(out uriChars);
string retval = Bitter.ToString2(uriChars);
delete uriChars;
return retval;
}
2008-11-17 18:29:00 -05:00
finally {
2008-03-05 09:52:00 -05:00
m_Conn.Release(conn);
}
}
public string GetQueryString()
{
HttpRequestContract.Imp conn = m_Conn.Acquire();
2008-11-17 18:29:00 -05:00
try {
2008-03-05 09:52:00 -05:00
char[] in ExHeap queryChars;
conn.SendGetQueryString();
conn.RecvQueryString(out queryChars);
2008-11-17 18:29:00 -05:00
if (queryChars != null) {
2008-03-05 09:52:00 -05:00
string retval = Bitter.ToString(queryChars);
delete queryChars;
return retval;
}
2008-11-17 18:29:00 -05:00
else {
2008-03-05 09:52:00 -05:00
return null;
}
}
2008-11-17 18:29:00 -05:00
finally {
2008-03-05 09:52:00 -05:00
m_Conn.Release(conn);
}
}
public string GetVerb()
{
HttpRequestContract.Imp conn = m_Conn.Acquire();
2008-11-17 18:29:00 -05:00
try {
2008-03-05 09:52:00 -05:00
char[]! in ExHeap verbChars;
conn.SendGetVerb();
conn.RecvVerb(out verbChars);
string retval = Bitter.ToString(verbChars);
delete verbChars;
return retval;
}
2008-11-17 18:29:00 -05:00
finally {
2008-03-05 09:52:00 -05:00
m_Conn.Release(conn);
}
}
public string GetHeader(string! headerName)
{
HttpRequestContract.Imp conn = m_Conn.Acquire();
2008-11-17 18:29:00 -05:00
try {
2008-03-05 09:52:00 -05:00
char[] in ExHeap headerChars;
conn.SendGetHeader(Bitter.FromString2(headerName));
conn.RecvHeaderValue(out headerChars);
if (headerChars != null) {
string retval = Bitter.ToString(headerChars);
delete headerChars;
return retval;
2008-11-17 18:29:00 -05:00
}
else {
2008-03-05 09:52:00 -05:00
return null;
}
}
2008-11-17 18:29:00 -05:00
finally {
2008-03-05 09:52:00 -05:00
m_Conn.Release(conn);
}
}
public byte[] GetBodyData()
{
HttpRequestContract.Imp conn = m_Conn.Acquire();
2008-11-17 18:29:00 -05:00
try {
2008-03-05 09:52:00 -05:00
byte[] in ExHeap bodyBytes;
conn.SendGetBody();
conn.RecvBodyData(out bodyBytes);
if (bodyBytes != null) {
byte[] retval = Bitter.ToByteArray(bodyBytes);
delete bodyBytes;
return retval;
2008-11-17 18:29:00 -05:00
}
else {
2008-03-05 09:52:00 -05:00
return null;
}
}
2008-11-17 18:29:00 -05:00
finally {
2008-03-05 09:52:00 -05:00
m_Conn.Release(conn);
}
}
public string! GetRemoteAddress()
{
HttpRequestContract.Imp conn = m_Conn.Acquire();
2008-11-17 18:29:00 -05:00
try {
2008-03-05 09:52:00 -05:00
char[]! in ExHeap addrChars;
conn.SendGetRemoteAddress();
conn.RecvRemoteAddress(out addrChars);
string! retval = Bitter.ToString2(addrChars);
delete addrChars;
return retval;
}
2008-11-17 18:29:00 -05:00
finally {
2008-03-05 09:52:00 -05:00
m_Conn.Release(conn);
}
}
public void SendStatus(int code, string! description)
{
HttpRequestContract.Imp conn = m_Conn.Acquire();
2008-11-17 18:29:00 -05:00
try {
2008-03-05 09:52:00 -05:00
char[]! in ExHeap descChars = Bitter.FromString2(description);
conn.SendSendStatus(code, descChars);
conn.RecvOK();
}
2008-11-17 18:29:00 -05:00
finally {
2008-03-05 09:52:00 -05:00
m_Conn.Release(conn);
}
}
public void SendHeader(string! name, string! value)
{
HttpRequestContract.Imp conn = m_Conn.Acquire();
2008-11-17 18:29:00 -05:00
try {
2008-03-05 09:52:00 -05:00
char[]! in ExHeap nameChars = Bitter.FromString2(name);
char[]! in ExHeap valChars = Bitter.FromString2(value);
conn.SendSendHeader(nameChars, valChars);
conn.RecvOK();
}
2008-11-17 18:29:00 -05:00
finally {
2008-03-05 09:52:00 -05:00
m_Conn.Release(conn);
}
}
public void SendBodyData(byte[]! data)
{
SendBodyData(Bitter.FromByteArray(data));
}
public void SendBodyData([Claims]byte[]! in ExHeap data)
{
HttpRequestContract.Imp conn = m_Conn.Acquire();
2008-11-17 18:29:00 -05:00
try {
2008-03-05 09:52:00 -05:00
conn.SendSendBodyData(data);
conn.RecvOK();
}
2008-11-17 18:29:00 -05:00
finally {
2008-03-05 09:52:00 -05:00
m_Conn.Release(conn);
}
}
public void Done()
{
HttpRequestContract.Imp conn = m_Conn.Acquire();
conn.SendDone();
delete conn;
}
}
}