コード例 #1
0
        /// <summary>
        /// Creates a new HTTPHeader, which is a clone of the given response.
        /// If the given HTTPHeader is not a response header this method returns null.
        /// If the given HTTPHeader was initialized empty and is not yet complete this method returns null.
        /// Otherwise it returns a clone of the given header.
        /// That is, it will have the same HTTP version, status code and description.
        /// Also, the headers will be a clone of the headers in the given response,
        /// but changes to the new headers will not affect the original headers.
        /// </summary>
        /// <param name="response">
        ///		A complete HTTPHeader response instance to create a clone of.
        /// </param>
        /// <returns>
        ///		Null if given an improper parameter. A clone of the original HTTPHeader otherwise.
        /// </returns>
        public static HTTPHeader CreateResponse(HTTPHeader response)
        {
            if (response.isRequest)
            {
                return(null);
            }

            if (response.isEmpty)
            {
                if (!response.IsHeaderComplete())
                {
                    return(null);
                }
                if (response.headers == null)
                {
                    response.ParseResponse();
                }
            }

            HTTPHeader clone = new HTTPHeader(false, false);

            clone.httpVersion       = response.httpVersion;
            clone.statusCode        = response.statusCode;
            clone.statusDescription = response.statusDescription;
            clone.headers           = new Dictionary <String, String>(response.headers, StringComparer.OrdinalIgnoreCase);

            return(clone);
        }
コード例 #2
0
        /// <summary>
        /// Creates a new HTTPHeader, which is a clone of the given request.
        /// If the given HTTPHeader is not a request header this method returns null.
        /// If the given HTTPHeader was initialized empty and is not yet complete this method returns null.
        /// Otherwise it returns a clone of the given header.
        /// That is, it will have the same HTTP version, request method and URL.
        /// Also, the headers will be a clone of the headers in the given request,
        /// but changes to the new headers will not affect the original headers.
        /// </summary>
        /// <param name="request">
        ///		A complete HTTPHeader request instance to create a clone of.
        /// </param>
        /// <returns>
        ///		Null if given an improper parameter. A clone of the original HTTPHeader otherwise.
        /// </returns>
        public static HTTPHeader CreateRequest(HTTPHeader request)
        {
            if (!request.isRequest)
            {
                return(null);
            }

            if (request.isEmpty)
            {
                if (!request.IsHeaderComplete())
                {
                    return(null);
                }
                if (request.headers == null)
                {
                    request.ParseRequest();
                }
            }

            HTTPHeader clone = new HTTPHeader(true, false);

            clone.httpVersion   = request.httpVersion;
            clone.requestMethod = request.requestMethod;
            clone.requestURL    = request.requestURL;
            clone.headers       = new Dictionary <String, String>(request.headers, StringComparer.OrdinalIgnoreCase);

            return(clone);
        }
コード例 #3
0
        /// <summary>
        /// Creates a new HTTPHeader, initialized as a request with the given method and URL.
        /// Use the setHeaderFieldValue method to set other HTTP header values,
        /// and use the overriden ToString() method to get the full finished header.
        /// </summary>
        /// <param name="requestMethod">
        ///		The HTTP command (eg. "GET")
        /// </param>
        /// <param name="requestURL">
        ///		The HTTP request (eg. "index.html")
        /// </param>
        /// <returns>
        ///		A new HTTPHeader instance, initialized non-empty as a request with the given information.
        /// </returns>
        public static HTTPHeader CreateRequest(String requestMethod, String requestURL)
        {
            HTTPHeader request = new HTTPHeader(true, false);

            request.requestMethod = requestMethod;
            request.requestURL    = requestURL;

            return(request);
        }
コード例 #4
0
        /// <summary>
        /// Create a new HTTPHeader, initialized as a response with the given status code and description.
        /// Use the setHeaderFieldValue method to set other HTTP header values,
        /// and use the overriden ToString method to get the full finished header.
        /// </summary>
        /// <param name="statusCode">
        ///		The HTTP status code (eg. 404)
        /// </param>
        /// <param name="statusDescription">
        ///		The HTTP status description (eg. "Not Found")
        /// </param>
        /// <returns>
        ///		A new HTTPHeader instance, initialized non-empty as a response with the given information.
        /// </returns>
        public static HTTPHeader CreateResponse(int statusCode, String statusDescription)
        {
            HTTPHeader response = new HTTPHeader(false, false);

            response.statusCode        = statusCode;
            response.statusDescription = statusDescription;

            return(response);
        }
コード例 #5
0
        /// <summary>
        /// Creates a new HTTPHeader, which is a clone of the given response.
        /// If the given HTTPHeader is not a response header this method returns null.
        /// If the given HTTPHeader was initialized empty and is not yet complete this method returns null.
        /// Otherwise it returns a clone of the given header.
        /// That is, it will have the same HTTP version, status code and description.
        /// Also, the headers will be a clone of the headers in the given response,
        /// but changes to the new headers will not affect the original headers.
        /// </summary>
        /// <param name="response">
        ///		A complete HTTPHeader response instance to create a clone of.
        /// </param>
        /// <returns>
        ///		Null if given an improper parameter. A clone of the original HTTPHeader otherwise.
        /// </returns>
        public static HTTPHeader CreateResponse(HTTPHeader response)
        {
            if (response.isRequest) return null;

            if (response.isEmpty)
            {
                if (!response.IsHeaderComplete()) return null;
                if (response.headers == null) response.ParseResponse();
            }

            HTTPHeader clone = new HTTPHeader(false, false);
            clone.httpVersion = response.httpVersion;
            clone.statusCode = response.statusCode;
            clone.statusDescription = response.statusDescription;
            clone.headers = new Dictionary<String, String>(response.headers, StringComparer.OrdinalIgnoreCase);

            return clone;
        }
コード例 #6
0
        /// <summary>
        /// Create a new HTTPHeader, initialized as a response with the given status code and description.
        /// Use the setHeaderFieldValue method to set other HTTP header values,
        /// and use the overriden ToString method to get the full finished header.
        /// </summary>
        /// <param name="statusCode">
        ///		The HTTP status code (eg. 404)
        /// </param>
        /// <param name="statusDescription">
        ///		The HTTP status description (eg. "Not Found")
        /// </param>
        /// <returns>
        ///		A new HTTPHeader instance, initialized non-empty as a response with the given information.
        /// </returns>
        public static HTTPHeader CreateResponse(int statusCode, String statusDescription)
        {
            HTTPHeader response = new HTTPHeader(false, false);
            response.statusCode = statusCode;
            response.statusDescription = statusDescription;

            return response;
        }
コード例 #7
0
        /// <summary>
        /// Creates a new HTTPHeader, which is a clone of the given request.
        /// If the given HTTPHeader is not a request header this method returns null.
        /// If the given HTTPHeader was initialized empty and is not yet complete this method returns null.
        /// Otherwise it returns a clone of the given header.
        /// That is, it will have the same HTTP version, request method and URL.
        /// Also, the headers will be a clone of the headers in the given request,
        /// but changes to the new headers will not affect the original headers.
        /// </summary>
        /// <param name="request">
        ///		A complete HTTPHeader request instance to create a clone of.
        /// </param>
        /// <returns>
        ///		Null if given an improper parameter. A clone of the original HTTPHeader otherwise.
        /// </returns>
        public static HTTPHeader CreateRequest(HTTPHeader request)
        {
            if (!request.isRequest) return null;

            if (request.isEmpty)
            {
                if (!request.IsHeaderComplete()) return null;
                if (request.headers == null) request.ParseRequest();
            }

            HTTPHeader clone = new HTTPHeader(true, false);
            clone.httpVersion = request.httpVersion;
            clone.requestMethod = request.requestMethod;
            clone.requestURL = request.requestURL;
            clone.headers = new Dictionary<String, String>(request.headers, StringComparer.OrdinalIgnoreCase);

            return clone;
        }
コード例 #8
0
        /// <summary>
        /// Creates a new HTTPHeader, initialized as a request with the given method and URL.
        /// Use the setHeaderFieldValue method to set other HTTP header values,
        /// and use the overriden ToString() method to get the full finished header.
        /// </summary>
        /// <param name="requestMethod">
        ///		The HTTP command (eg. "GET")
        /// </param>
        /// <param name="requestURL">
        ///		The HTTP request (eg. "index.html")
        /// </param>
        /// <returns>
        ///		A new HTTPHeader instance, initialized non-empty as a request with the given information.
        /// </returns>
        public static HTTPHeader CreateRequest(String requestMethod, String requestURL)
        {
            HTTPHeader request = new HTTPHeader(true, false);
            request.requestMethod = requestMethod;
            request.requestURL = requestURL;

            return request;
        }
コード例 #9
0
 /// <summary>
 /// Creates a new empty HTTPHeader, initialized as a response.
 /// Call appendByte(s) to add incoming data to the header,
 /// and use IsHeaderComplete to determine when you've received a full header.
 /// Finally, use the get methods to extract the desired information.
 /// </summary>
 /// <returns>
 ///		A new HTTPHeader instance, initialized empty as a response.
 ///	</returns>
 public static HTTPHeader CreateEmptyResponse()
 {
     HTTPHeader response = new HTTPHeader(false, true);
     return response;
 }
コード例 #10
0
 /// <summary>
 /// Creates a new empty HTTPHeader, initialized as a request.
 /// Call appendByte(s) to add incoming data to the header,
 /// and use IsHeaderComplete to determine when you've received a full header.
 /// Finally, use the get methods to extract the desired information.
 /// </summary>
 /// <returns>
 ///		A new HTTPHeader instance, initialized empty as a request.
 ///	</returns>
 public static HTTPHeader CreateEmptyRequest()
 {
     HTTPHeader request = new HTTPHeader(true, true);
     return request;
 }
コード例 #11
0
ファイル: Form1.cs プロジェクト: Gemini2015/dotnetasyncsocket
        private void SendRequest()
        {
            // Record when we first started the download
            headerLength = 0;
            startTime = DateTime.Now;

            // Create a HTTP request using the Deusty.Net.HTTP.HTTPHeader class.
            // The HTTP protocol is fairly straightforward, but this class helps hide protocol
            // specific information that we're not really concerned with for this AsyncSocket sameple.

            HTTPHeader request = HTTPHeader.CreateRequest("GET", FETCH_REQUEST);
            request.SetHeaderFieldValue("Host", FETCH_HOST);

            String requestStr = request.ToString();

            LogInfo("Sending Request:");
            LogMessage(requestStr);

            // Convert HTTPHeader object to a byte array.

            byte[] requestData = Encoding.UTF8.GetBytes(requestStr);
            Console.WriteLine(Data.ToHexString(requestData));

            // Now write the data over the socket.
            // This call is asynchronous, and returns immediately.
            // When finished writing, the asyncSocket_DidWrite method is called.

            asyncSocket.Write(requestData, WRITE_TIMEOUT, HTTP_HEADERS);

            // Setup http response
            response = HTTPHeader.CreateEmptyResponse();

            // And start reading in the response
            asyncSocket.Read(AsyncSocket.CRLFData, READ_HEADER_TIMEOUT, HTTP_HEADERS);

            // Reset progress bar
            progressBar.Value = 0;
        }
コード例 #12
0
        /// <summary>
        /// Creates a new empty HTTPHeader, initialized as a response.
        /// Call appendByte(s) to add incoming data to the header,
        /// and use IsHeaderComplete to determine when you've received a full header.
        /// Finally, use the get methods to extract the desired information.
        /// </summary>
        /// <returns>
        ///		A new HTTPHeader instance, initialized empty as a response.
        ///	</returns>
        public static HTTPHeader CreateEmptyResponse()
        {
            HTTPHeader response = new HTTPHeader(false, true);

            return(response);
        }
コード例 #13
0
        /// <summary>
        /// Creates a new empty HTTPHeader, initialized as a request.
        /// Call appendByte(s) to add incoming data to the header,
        /// and use IsHeaderComplete to determine when you've received a full header.
        /// Finally, use the get methods to extract the desired information.
        /// </summary>
        /// <returns>
        ///		A new HTTPHeader instance, initialized empty as a request.
        ///	</returns>
        public static HTTPHeader CreateEmptyRequest()
        {
            HTTPHeader request = new HTTPHeader(true, true);

            return(request);
        }