public ReplyBase(Http.Response response) { _response = response; if (_response.StatusLine.StatusCode >= 400 && _response.StatusLine.StatusCode < 500) Error = new Error(response); else ParseResponse(); }
void OnComplete(ClientLib.Client sender, Http.HttpConnection connection, Http.Response httpResponse, Api.Responses.ResponseBase apiResponse, TimeSpan duration) { Api.Responses.Pong resp = (Api.Responses.Pong)apiResponse; WriteLine("Server execution time: " + resp.Duration.Milliseconds.ToString() + "ms."); WriteLine("Round-trip completed in " + (DateTime.Now - _start).Milliseconds.ToString() + "ms."); WriteLine("JSON response:\r\n" + resp.FullContent.ToString()); }
public override ReplyBase MakeReply(Http.Response response) { try { return(new PutDatabaseReply(response)); } catch (Exception e) { Logger.Storage.Error("An exception occurred while creating the PutDatabaseReply.", e); throw; } }
public ReplyBase(Http.Response response) { _response = response; if (_response.StatusLine.StatusCode >= 400 && _response.StatusLine.StatusCode < 500) { Error = new Error(response); } else { ParseResponse(); } }
public DeleteDocumentReply(Http.Response response) : base(response) { }
public HeadDocumentReply(Http.Response response) : base(response) { }
public override void Parse() { // A status line will always be first, its possible another status line will follow // (consider 100 continue then a 404) int index; string newpacket; newpacket = BytesToString(_remainingBuffer, 0, _remainingBufferAppendPosition); if ((index = newpacket.IndexOf("\r\n\r\n")) < 0) { // Ending sequence is not found, we need to append to our string and wait for // Parse to get called again. _firstLineAndHeaders += newpacket; // Clear _remainingBuffer since it was all used _remainingBuffer = null; _remainingBufferAppendPosition = 0; if (!string.IsNullOrEmpty(_firstLineAndHeaders) && newpacket.StartsWith("HTTP") && newpacket.Contains("\r\n")) { string temp = newpacket.Substring(0, newpacket.IndexOf("\r\n")); Response.StatusLine = StatusLine.Parse(temp); } } else { string[] parts; List<string> lines; int loop = 0; // index + 4 = how many bytes to skip in _remainingBuffer then tie the stream to the // Response.Body // Possible index placements (index < 0 is handled and index >= newpacket.length-4 is impossible // 1) index == 0 // 2) index between 0 and newpacket.length-4 // Append the headers from newpacket to the other status and headers _firstLineAndHeaders += newpacket.Substring(0, index); // Reduce the buffer by the removed bytes _remainingBuffer = TrimStartBuffer(_remainingBuffer, index+4); // +4 because we want to remove the trailing \r\n\r\n also // Reduce the append position by the number of removed bytes _remainingBufferAppendPosition -= index+4; // +4 for same reason lines = GetLines(_firstLineAndHeaders); // We cycle thru the lines to get the most recent status line while (lines[loop].StartsWith("HTTP")) { loop++; } if (Response != null && Response.StatusLine != null && !string.IsNullOrEmpty(Response.StatusLine.HttpVersion)) { // If we are here, we have received a 100-continue status earlier if (Response.StatusLine.StatusCode != 100) throw new HttpNetworkStreamException("Unexpected status code."); } else { // If we are here, we have no status line yet, need to parse one if (loop <= 0) throw new HttpNetworkStreamException("Status line not found."); // Now loop holds the index of the NEXT line after the last HTTP line, so decrement 1 // to get back to the index loop--; Response = new Response(Request); Response.StatusLine = StatusLine.Parse(lines[loop]); } // No matter if we received the 100 or not, we can now parse headers Response.Headers.Clear(); // We go loop+1 because we want to skip the status line for (int i = loop+1; i < lines.Count; i++) { parts = new string[2]; parts[0] = lines[i].Substring(0, lines[i].IndexOf(':')).Trim(); parts[1] = lines[i].Substring(lines[i].IndexOf(':') + 1).Trim(); Response.Headers.Add(new Message.Token(parts[0]), parts[1]); } AllHeadersReceived = true; } }
public HeadAttachmentReply(Http.Response response) : base(response) { }
public PutDatabaseReply(Http.Response response) : base(response) { }
public abstract ReplyBase MakeReply(Http.Response response);
public GetDocumentReply(Http.Response response) : base(response) { }
public PostBulkDocumentsReply(Http.Response response) : base(response) { }
public DeleteAttachmentReply(Http.Response response) : base(response) { }
public DeleteDatabaseReply(Http.Response response) : base(response) { }
public Error(Http.Response response) { //response.Stream.OnTimeout += new HttpNetworkStream.TimeoutDelegate(Stream_OnTimeout); //response.Stream.OnError += new HttpNetworkStream.ErrorDelegate(Stream_OnError); //response.Stream.OnStringOperationComplete += new HttpNetworkStream.CompleteStringOperationDelegate(Stream_OnStringOperationComplete); Logger.Storage.Debug("Forming error package..."); //response.Stream.ReadToEndAsync(); try { // Head method receives a content length but does not receive content, so we would wait a timeout to get a response // causing all kinds of problems. if (response.Request.RequestLine.Method.GetType() != typeof(Http.Methods.Head)) { if (response.Body.ReceiveStream.GetType() != typeof(Networking.Protocols.Http.HttpNetworkStream)) { throw new OpenDMS.Networking.Protocols.Http.HttpNetworkStreamException("Invalid stream type."); } string str = ((Networking.Protocols.Http.HttpNetworkStream)response.Body.ReceiveStream).ReadToEnd(); if (str != null && str != "") { JObject jobj = JObject.Parse(str); if (jobj["error"] != null) { ErrorType = jobj["error"].Value <string>(); } if (jobj["id"] != null) { Id = jobj["id"].Value <string>(); } if (jobj["reason"] != null) { Reason = jobj["reason"].Value <string>(); } } else { ErrorType = "unknown"; Id = null; Reason = "Unknown"; } } else { ErrorType = "unknown"; Id = null; Reason = "Unknown"; } } catch (System.Exception e) { Logger.Storage.Error("An exception occurred while creating the Error object.", e); throw; } Logger.Storage.Debug("Error package loaded."); }
public GetViewReply(Http.Response response) : base(response) { }