/// <summary> /// Parses the request line of a batch operation request. /// </summary> /// <param name="requestLine">The request line as a string.</param> /// <param name="httpMethod">The parsed HTTP method of the request.</param> /// <param name="requestUri">The parsed <see cref="Uri"/> of the request.</param> private void ParseRequestLine(string requestLine, out string httpMethod, out Uri requestUri) { Debug.Assert(!this.inputContext.ReadingResponse, "Must only be called for requests."); // Batch Request: POST /Customers HTTP/1.1 // Since the uri can contain spaces, the only way to read the request url, is to // check for first space character and last space character and anything between // them. int firstSpaceIndex = requestLine.IndexOf(' '); // Check whether there are enough characters after the first space for the 2nd and 3rd segments // (and a whitespace in between) if (firstSpaceIndex <= 0 || requestLine.Length - 3 <= firstSpaceIndex) { // only 1 segment or empty first segment or not enough left for 2nd and 3rd segments throw new ODataException(Strings.ODataBatchReaderStream_InvalidRequestLine(requestLine)); } int lastSpaceIndex = requestLine.LastIndexOf(' '); if (lastSpaceIndex < 0 || lastSpaceIndex - firstSpaceIndex - 1 <= 0 || requestLine.Length - 1 <= lastSpaceIndex) { // only 2 segments or empty 2nd or 3rd segments // only 1 segment or empty first segment or not enough left for 2nd and 3rd segments throw new ODataException(Strings.ODataBatchReaderStream_InvalidRequestLine(requestLine)); } httpMethod = requestLine.Substring(0, firstSpaceIndex); // Request - Http method string uriSegment = requestLine.Substring(firstSpaceIndex + 1, lastSpaceIndex - firstSpaceIndex - 1); // Request - Request uri string httpVersionSegment = requestLine.Substring(lastSpaceIndex + 1); // Request - Http version // Validate HttpVersion if (string.CompareOrdinal(ODataConstants.HttpVersionInBatching, httpVersionSegment) != 0) { throw new ODataException(Strings.ODataBatchReaderStream_InvalidHttpVersionSpecified(httpVersionSegment, ODataConstants.HttpVersionInBatching)); } // NOTE: this method will throw if the method is not recognized. HttpUtils.ValidateHttpMethod(httpMethod); // Validate the HTTP method when reading a request if (this.batchStream.ChangeSetBoundary != null) { // allow all methods except for GET if (HttpUtils.IsQueryMethod(httpMethod)) { throw new ODataException(Strings.ODataBatch_InvalidHttpMethodForChangeSetRequest(httpMethod)); } } requestUri = new Uri(uriSegment, UriKind.RelativeOrAbsolute); requestUri = ODataBatchUtils.CreateOperationRequestUri(requestUri, this.inputContext.MessageReaderSettings.BaseUri, this.payloadUriConverter); }