public void Finish(HttpEntity entity) { if (state == State.InKey) throw new HttpException ("Malformed POST data, key found without value."); FinishPair (entity); }
public void WriteMetadata(WriteCallback callback) { if (pending_length_cbs > 0) { return; } if (AddHeaders) { if (chunk_encode) { HttpEntity.Headers.SetNormalizedHeader("Transfer-Encoding", "chunked"); } else { HttpEntity.Headers.ContentLength = Length; } } StringBuilder builder = new StringBuilder(); HttpEntity.WriteMetadata(builder); byte [] data = Encoding.ASCII.GetBytes(builder.ToString()); metadata_written = true; var bytes = new List <ByteBuffer> (); bytes.Add(new ByteBuffer(data, 0, data.Length)); var write_bytes = new SendBytesOperation(bytes.ToArray(), callback); SocketStream.QueueWriteOperation(write_bytes); }
public void HandleData(HttpEntity entity, ByteBuffer data, int pos, int len) { if (builder == null) builder = new StringBuilder(); string str = entity.ContentEncoding.GetString(data.Bytes, pos, len); builder.Append(str); }
public void Finish(HttpEntity entity) { if (state == State.InKey && key_buffer.Length > 0) { throw new HttpException("Malformed POST data, key found without value."); } FinishPair(entity); }
public void HandleData(HttpEntity entity, ByteBuffer data, int pos, int len) { if (builder == null) { builder = new StringBuilder(); } string str = entity.ContentEncoding.GetString(data.Bytes, pos, len); builder.Append(str); }
public static void AddBasicAuthentication(HttpEntity entity, string user, string password) { if (entity == null) throw new ArgumentNullException ("entity"); if (user == null) throw new ArgumentNullException ("user"); if (password == null) throw new ArgumentNullException ("password"); string authd = user + ":" + password; entity.Headers.SetNormalizedHeader ("Authorization", "Basic " + Convert.ToBase64String (Encoding.ASCII.GetBytes (authd))); }
private void FinishFormData(HttpEntity entity) { if (form_data.Count == 0) { return; } string data = encoding.GetString(form_data.ToArray()); entity.PostData.Set(current_name, HttpUtility.UrlDecode(data, encoding)); form_data.Clear(); }
private void FinishFormData(HttpEntity entity) { if (form_data.Count <= 2) { return; } // Chop the \r\n off the end form_data.RemoveRange(form_data.Count - 2, 2); string data = encoding.GetString(form_data.ToArray()); entity.PostData.Set(current_name, data); form_data.Clear(); }
private void HandleHeader(HttpEntity entity) { string key = encoding.GetString(header_key.ToArray()); string value = encoding.GetString(header_value.ToArray()); if (String.Compare(key, "Content-Disposition", true) == 0) { ParseContentDisposition(value); } else if (String.Compare(key, "Content-Type", true) == 0) { ParseContentType(value); } }
private void FinishPair(HttpEntity entity) { if (key_buffer.Length == 0) { throw new HttpException("zero length key in www-form data."); } Encoding e = entity.ContentEncoding; entity.PostData.Set(HttpUtility.UrlDecode(key_buffer.ToString(), e), HttpUtility.UrlDecode(value_buffer.ToString(), e)); key_buffer.Length = 0; value_buffer.Length = 0; }
public void HandleData(HttpEntity entity, ByteBuffer data, int pos, int len) { string str_data = entity.ContentEncoding.GetString(data.Bytes, pos, len); str_data = HttpUtility.HtmlDecode(str_data); pos = 0; len = str_data.Length; while (pos < len) { char c = str_data [pos++]; if (c == '&') { if (state == State.InKey) { throw new InvalidOperationException("& symbol can not be used in key data."); } FinishPair(entity); state = State.InKey; continue; } if (c == '=') { if (state == State.InValue) { throw new InvalidOperationException("= symbol can not be used in value data."); } state = State.InValue; continue; } switch (state) { case State.InKey: key_buffer.Append(c); break; case State.InValue: value_buffer.Append(c); break; } } }
public void WriteMetadata(WriteCallback callback) { StringBuilder builder = new StringBuilder(); HttpEntity.WriteMetadata(builder); byte [] data = Encoding.ASCII.GetBytes(builder.ToString()); metadata_written = true; var bytes = new List <ArraySegment <byte> > (); bytes.Add(new ArraySegment <byte> (data, 0, data.Length)); var write_bytes = new SendBytesOperation(bytes, callback); SocketStream.QueueWriteOperation(write_bytes); }
private void FinishFileData(HttpEntity entity) { if (uploaded_file == null) { return; } // Chop off the \r\n that gets appended before the boundary marker uploaded_file.Contents.SetLength(uploaded_file.Contents.Position - 2); uploaded_file.Finish(); if (uploaded_file.Length > 0) { entity.Files.Add(current_name, uploaded_file); } uploaded_file = null; }
public static void AddBasicAuthentication(HttpEntity entity, string user, string password) { if (entity == null) { throw new ArgumentNullException("entity"); } if (user == null) { throw new ArgumentNullException("user"); } if (password == null) { throw new ArgumentNullException("password"); } string authd = user + ":" + password; entity.Headers.SetNormalizedHeader("Authorization", "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(authd))); }
public void HandleData(HttpEntity entity, ByteBuffer data, int pos, int len) { string str_data = entity.ContentEncoding.GetString(data.Bytes, pos, len); str_data = HttpUtility.HtmlDecode(str_data); pos = 0; len = str_data.Length; while (pos < len) { char c = str_data[pos++]; if (c == '&') { if (state == State.InKey) throw new InvalidOperationException("& symbol can not be used in key data."); FinishPair(entity); state = State.InKey; continue; } if (c == '=') { if (state == State.InValue) throw new InvalidOperationException("= symbol can not be used in value data."); state = State.InValue; continue; } switch (state) { case State.InKey: key_buffer.Append(c); break; case State.InValue: value_buffer.Append(c); break; } } }
void WriteMetadata() { if (AddHeaders) { if (chunk_encode) { HttpEntity.Headers.SetNormalizedHeader("Transfer-Encoding", "chunked"); } else { HttpEntity.Headers.ContentLength = Length; } } StringBuilder builder = new StringBuilder(); HttpEntity.WriteMetadata(builder); byte [] data = Encoding.ASCII.GetBytes(builder.ToString()); metadata_written = true; SocketStream.Write(data); }
public HttpStream(HttpEntity entity, Manos.IO.IByteStream stream) { HttpEntity = entity; SocketStream = stream; AddHeaders = true; }
public void Finish(HttpEntity entity) { entity.PostBody = builder.ToString(); }
private void FinishPair(HttpEntity entity) { if (value_buffer.Length == 0) return; if (key_buffer.Length == 0) throw new HttpException ("zero length key in www-form data."); Encoding e = entity.ContentEncoding; entity.PostData.Set (HttpUtility.UrlDecode (key_buffer.ToString (), e), HttpUtility.UrlDecode (value_buffer.ToString (), e)); key_buffer.Clear (); value_buffer.Clear (); }
private void HandleHeader(HttpEntity entity) { string key = System.Text.Encoding.ASCII.GetString (header_key.ToArray ()).Trim (); string value = System.Text.Encoding.UTF8.GetString (header_value.ToArray ()).Trim (); if (String.Compare(key,"Content-Disposition",true) == 0) { ParseContentDisposition (value, entity); if (uploaded_file != null && uploaded_file.FileRef != null) { entity.AddInProgressFile (uploaded_file.FileRef, uploaded_file); } } else if (String.Compare(key,"Content-Type",true) == 0) { ParseContentType (value); } }
public HttpStream(HttpEntity entity, SocketStream stream) { HttpEntity = entity; SocketStream = stream; }
public void ParseContentDisposition(string UTF8string, HttpEntity entity) { current_name = GetContentDispositionAttribute (UTF8string, "name"); current_filename = GetContentDispositionAttribute (UTF8string, "filename"); if (!String.IsNullOrEmpty (current_filename)) { string fileRef = null; if (entity is HttpRequest) { Manos.Collections.DataDictionary queryData = null; if (((HttpRequest) entity).QueryDataString.Length != 0) { queryData = HttpUtility.ParseUrlEncodedData (((HttpRequest) entity).QueryDataString); } fileRef = queryData ["ref"]; } uploaded_file = file_creator.Create (current_filename, fileRef, entity.Headers.ContentLength); } }
private void FinishFormData(HttpEntity entity) { if (form_data.Count <= 2) return; // Chop the \r\n off the end form_data.RemoveRange (form_data.Count - 2, 2); string data = encoding.GetString (form_data.ToArray ()); entity.PostData.Set (current_name, data); form_data.Clear (); }
private void FinishPair(HttpEntity entity) { if (key_buffer.Length == 0) throw new HttpException ("zero length key in www-form data."); //Encoding e = entity.ContentEncoding; entity.PostData.Set(Uri.UnescapeDataString(key_buffer.ToString()), Uri.UnescapeDataString(value_buffer.ToString())); key_buffer.Length = 0; value_buffer.Length = 0; }
public HttpStream(HttpEntity entity, ISocketStream stream) { HttpEntity = entity; SocketStream = stream; AddHeaders = true; }
public HttpStream(HttpEntity entity, SocketStream stream) { HttpEntity = entity; SocketStream = stream; AddHeaders = true; }
public void HandleData(HttpEntity entity, ByteBuffer data, int pos, int len) { // string str_data = encoding.GetString (data.Bytes, pos, len); byte [] str_data = data.Bytes; int begin = pos; int end = begin + len; pos = begin - 1; while (pos < end - 1 && state != State.Finished) { byte c = str_data [++pos]; switch (state) { case State.InBoundary: if (c == '\r') break; if (c == '\n') break; if (index == boundary.Length - 1) { boundary_buffer.Clear (); // Flush any data FinishFormData (entity); FinishFileData (entity); state = State.PostBoundary1; index = 0; break; } boundary_buffer.Add (c); if (c != boundary [index]) { // Copy the boundary buffer to the beginning and restart parsing there MemoryStream stream = new MemoryStream (); stream.Write (boundary_buffer.ToArray (), 0, boundary_buffer.Count); stream.Write (str_data, pos + 1, end - pos - 1); str_data = stream.ToArray (); pos = -1; end = str_data.Length; not_boundary = true; boundary_buffer.Clear (); state = previous_state; index = 0; // continue instead of break so not_boundary is not reset continue; } ++index; break; case State.PostBoundary1: if (c == '-') { state = State.PostBoundaryComplete; break; } if (c == '\r') break; if (c == '\n') { state = State.InHeaderKey; break; } throw new Exception (String.Format ("Invalid post boundary char '{0}'", c)); case State.PostBoundaryComplete: if (c != '-') throw new Exception (String.Format ("Invalid char '{0}' in boundary complete.", c)); state = State.Finished; break; case State.InHeaderKey: if (c == '\n') { state = current_filename == null ? State.InFormData : State.InFileData; break; } if (c == ':') { state = State.InHeaderValue; break; } header_key.Add (c); break; case State.InHeaderValue: if (c == '\r') { state = State.PostHeader1; break; } header_value.Add (c); break; case State.PostHeader1: if (c != '\n') throw new Exception (String.Format ("Invalid char '{0}' in post header 1.", c)); HandleHeader (entity); header_key.Clear (); header_value.Clear (); state = State.InHeaderKey; break; case State.InFormData: if (CheckStartingBoundary (str_data, pos)) break; form_data.Add (c); break; case State.InFileData: if (CheckStartingBoundary (str_data, pos)) break;; if (uploaded_file != null) uploaded_file.Contents.WriteByte (c); break; default: throw new Exception (String.Format ("Unhandled state: {0}", state)); } not_boundary = false; } }
public void Finish(HttpEntity entity) { FinishFormData(entity); FinishFileData(entity); }
public void Finish(HttpEntity entity) { FinishFormData (entity); FinishFileData (entity); }
public void HandleData(HttpEntity entity, ByteBuffer data, int pos, int len) { // string str_data = encoding.GetString (data.Bytes, pos, len); byte [] str_data = data.Bytes; int begin = pos; int end = begin + len; pos = begin - 1; while (pos < end - 1 && state != State.Finished) { byte c = str_data [++pos]; switch (state) { case State.InBoundary: if (c == '\r') { break; } if (c == '\n') { break; } if (index == boundary.Length - 1) { boundary_buffer.Clear(); // Flush any data FinishFormData(entity); FinishFileData(entity); state = State.PostBoundary1; index = 0; break; } boundary_buffer.Add(c); if (c != boundary [index]) { // Copy the boundary buffer to the beginning and restart parsing there MemoryStream stream = new MemoryStream(); stream.Write(boundary_buffer.ToArray(), 0, boundary_buffer.Count); stream.Write(str_data, pos + 1, end - pos - 1); str_data = stream.ToArray(); pos = -1; end = str_data.Length; not_boundary = true; boundary_buffer.Clear(); state = previous_state; index = 0; // continue instead of break so not_boundary is not reset continue; } ++index; break; case State.PostBoundary1: if (c == '-') { state = State.PostBoundaryComplete; break; } if (c == '\r') { break; } if (c == '\n') { state = State.InHeaderKey; break; } throw new Exception(String.Format("Invalid post boundary char '{0}'", c)); case State.PostBoundaryComplete: if (c != '-') { throw new Exception(String.Format("Invalid char '{0}' in boundary complete.", c)); } state = State.Finished; break; case State.InHeaderKey: if (c == '\n') { state = current_filename == null ? State.InFormData : State.InFileData; break; } if (c == ':') { state = State.InHeaderValue; break; } header_key.Add(c); break; case State.InHeaderValue: if (c == '\r') { state = State.PostHeader1; break; } header_value.Add(c); break; case State.PostHeader1: if (c != '\n') { throw new Exception(String.Format("Invalid char '{0}' in post header 1.", c)); } HandleHeader(entity); header_key.Clear(); header_value.Clear(); state = State.InHeaderKey; break; case State.InFormData: if (CheckStartingBoundary(str_data, pos)) { break; } form_data.Add(c); break; case State.InFileData: if (CheckStartingBoundary(str_data, pos)) { break; } ; if (uploaded_file != null) { uploaded_file.Contents.WriteByte(c); } break; default: throw new Exception(String.Format("Unhandled state: {0}", state)); } not_boundary = false; } }
private void FinishFileData(HttpEntity entity) { if (uploaded_file == null) return; // Chop off the \r\n that gets appended before the boundary marker uploaded_file.Contents.SetLength (uploaded_file.Contents.Position - 2); uploaded_file.Finish (); if (uploaded_file.Length > 0) entity.Files.Add (current_name, uploaded_file); uploaded_file = null; }
private void HandleHeader(HttpEntity entity) { string key = encoding.GetString (header_key.ToArray ()); string value = encoding.GetString (header_value.ToArray ()); if (String.Compare(key,"Content-Disposition",true) == 0) ParseContentDisposition (value); else if (String.Compare(key,"Content-Type",true) == 0) ParseContentType (value); }
private void FinishFormData(HttpEntity entity) { if (form_data.Count == 0) return; string data = encoding.GetString (form_data.ToArray ()); entity.PostData.Set (current_name, HttpUtility.UrlDecode (data, encoding)); form_data.Clear (); }