示例#1
0
 public DubizzleURIBuilder(HTTPProtocol protocol, Localization location, MainSection section)
 {
     Location = location ;
     Protocol = protocol;
     Section = section;
     this.Url = new Uri(string.Format("{0}{1}.{2}/{3}", _protocolString, _locationString, baseuri, _sectionString));
 }
示例#2
0
        internal void ReadCookiesFromResponse(HttpResponse response)
        {
            lock (this) {
                Uri responseUri = response.RequestUri;
                HttpCookieCollection cookieColl = null;
                if (this.m_cookieStore.ContainsKey(responseUri.Host))
                {
                    cookieColl = this.m_cookieStore[responseUri.Host];
                }
                else
                {
                    cookieColl = new HttpCookieCollection();
                    this.m_cookieStore.Add(responseUri.Host, cookieColl);
                }

                string[] cookieHeaders = response.Headers.GetValues("Set-Cookie");
                if (cookieHeaders != null)
                {
                    foreach (string header in cookieHeaders)
                    {
                        HTTPProtocol.AddHttpCookie(header, cookieColl);
                    }
                }
            }
        }
        public UrlEncodedFormEntity(List <NameValuePair> parameters, Encoding encoding)
        {
            this.m_parameters = parameters;
            this.m_encoding   = encoding;

            StringBuilder stringBuilder = new StringBuilder();

            HTTPProtocol.AddPostParameters(this.m_parameters, stringBuilder);
            m_content = this.m_encoding.GetBytes(stringBuilder.ToString());
        }
示例#4
0
 public static string ToString(HttpEntity entity)
 {
     if (entity != null &&
         entity.Content != null)
     {
         return(HTTPProtocol.GetEncoding(entity.ContentType).GetString(entity.Content));
     }
     else
     {
         return(string.Empty);
     }
 }
示例#5
0
        internal void WriteCookiesToRequest(HttpRequest request)
        {
            string host = request.Uri.Host;

            if (this.m_cookieStore.ContainsKey(host))
            {
                HttpCookieCollection cookieColl = this.m_cookieStore[request.Uri.Host];
                if (cookieColl != null)
                {
                    request.Headers.Add("Cookie", HTTPProtocol.GetCookiesHeader(cookieColl));
                }
            }
        }
示例#6
0
        public byte[] GetContent(string boundry)
        {
            List <byte> bytes = new List <byte>();

            if (this.m_content.Length == 0 || this.m_mimeType == null || this.m_mimeType.Equals(string.Empty))
            {
                bytes.AddRange(Encoding.ASCII.GetBytes(HTTPProtocol.AddPostParametersFile(this.m_name, this.m_fileName, boundry, "application/octet-stream")));
            }
            else
            {
                bytes.AddRange(Encoding.ASCII.GetBytes(HTTPProtocol.AddPostParametersFile(this.m_name, this.m_fileName, boundry, this.m_mimeType)));
            }
            bytes.AddRange(this.m_content);
            bytes.AddRange(Encoding.ASCII.GetBytes("\r\n"));
            return(bytes.ToArray());
        }
示例#7
0
 public byte[] GetContent(string boundry)
 {
     return(this.m_encoding.GetBytes(HTTPProtocol.GetPostParameter(this.m_name, this.m_value, boundry)));
 }
示例#8
0
        IEnumerator ServeHTTP()
        {
            yield return(null);

            listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            var endPoint = new IPEndPoint(IPAddress.Any, port);

            listener.Bind(endPoint);
            listener.Listen(5);
            var background = new BackgroundTask();
            var foreground = new ForegroundTask();

            var host = "http://localhost:" + port.ToString();

            while (true)
            {
                yield return(background);

                Request       request = null;
                NetworkStream stream  = null;
                try {
                    var client = listener.Accept();
                    stream  = new NetworkStream(client);
                    request = Request.BuildFromStream(host, stream);
                } catch (HTTPException) {
                    Shutdown();
                    yield break;
                } catch (ThreadAbortException) {
                    Shutdown();
                    yield break;
                } catch (Exception e) {
                    Debug.LogError("Exception in server thread: " + e.ToString());
                    Shutdown();
                    yield break;
                }

                yield return(foreground);

                RouteRequest(request);
                yield return(background);

                try {
                    request.response.headers.Set("Connection", "Close");
                    HTTPProtocol.WriteResponse(stream, request.response.status, request.response.message, request.response.headers, request.response.Bytes);
                    stream.Flush();
                    stream.Dispose();
                } catch (HTTPException) {
                    Shutdown();
                    yield break;
                } catch (ThreadAbortException) {
                    Shutdown();
                    yield break;
                } catch (Exception e) {
                    Debug.LogError("Exception in server thread: " + e.ToString());
                    Shutdown();
                    yield break;
                }
                if (logRequests)
                {
                    Debug.Log(string.Format("{0} {1} {2} \"{3}\" {4}", System.DateTime.Now.ToString("yyyy/mm/dd H:mm:ss zzz"), request.response.status, request.method.ToUpper(), request.uri, request.response.Bytes.Length));
                }
            }
        }