/// <exception cref="System.IO.IOException"></exception> private void DoWriteTo(HttpMultipartMode mode, OutputStream @out, bool writeContent ) { ByteArrayBuffer boundary = Encode(this.charset, GetBoundary()); foreach (FormBodyPart part in this.parts) { WriteBytes(TwoDashes, @out); WriteBytes(boundary, @out); WriteBytes(CrLf, @out); Header header = part.GetHeader(); switch (mode) { case HttpMultipartMode.Strict: { foreach (MinimalField field in header) { WriteField(field, @out); } break; } case HttpMultipartMode.BrowserCompatible: { // Only write Content-Disposition // Use content charset MinimalField cd = part.GetHeader().GetField(MIME.ContentDisposition); WriteField(cd, this.charset, @out); string filename = part.GetBody().GetFilename(); if (filename != null) { MinimalField ct = part.GetHeader().GetField(MIME.ContentType); WriteField(ct, this.charset, @out); } break; } } WriteBytes(CrLf, @out); if (writeContent) { part.GetBody().WriteTo(@out); } WriteBytes(CrLf, @out); } WriteBytes(TwoDashes, @out); WriteBytes(boundary, @out); WriteBytes(TwoDashes, @out); WriteBytes(CrLf, @out); }
/// <summary>Creates an instance with the specified settings.</summary> /// <remarks>Creates an instance with the specified settings.</remarks> /// <param name="subType"> /// mime subtype - must not be /// <code>null</code> /// </param> /// <param name="charset"> /// the character set to use. May be /// <code>null</code> /// , in which case /// <see cref="MIME.DefaultCharset">MIME.DefaultCharset</see> /// - i.e. US-ASCII - is used. /// </param> /// <param name="boundary"> /// to use - must not be /// <code>null</code> /// </param> /// <param name="mode">the mode to use</param> /// <exception cref="System.ArgumentException">if charset is null or boundary is null /// </exception> public HttpMultipart(string subType, Encoding charset, string boundary, HttpMultipartMode mode) : base() { if (subType == null) { throw new ArgumentException("Multipart subtype may not be null"); } if (boundary == null) { throw new ArgumentException("Multipart boundary may not be null"); } this.subType = subType; this.charset = charset != null ? charset : MIME.DefaultCharset; this.boundary = boundary; this.parts = new AList <FormBodyPart>(); this.mode = mode; }
/// <summary>Creates an instance using the specified parameters</summary> /// <param name="mode"> /// the mode to use, may be /// <code>null</code> /// , in which case /// <see cref="HttpMultipartMode.Strict">HttpMultipartMode.Strict</see> /// is used /// </param> /// <param name="boundary"> /// the boundary string, may be /// <code>null</code> /// , in which case /// <see cref="GenerateBoundary()">GenerateBoundary()</see> /// is invoked to create the string /// </param> /// <param name="charset"> /// the character set to use, may be /// <code>null</code> /// , in which case /// <see cref="MIME.DefaultCharset">MIME.DefaultCharset</see> /// - i.e. US-ASCII - is used. /// </param> public MultipartEntity(HttpMultipartMode mode, string boundary, Encoding charset) : base() { // @GuardedBy("dirty") // we always read dirty before accessing length // used to decide whether to recalculate length if (boundary == null) { boundary = GenerateBoundary(); } if (mode == null) { mode = HttpMultipartMode.Strict; } this.multipart = new HttpMultipart("related", charset, boundary, mode); this.contentType = new BasicHeader(HTTP.ContentType, GenerateContentType(boundary , charset)); this.dirty = true; }
/// <summary> /// Creates an instance using the specified /// <see cref="HttpMultipartMode">HttpMultipartMode</see> /// mode. /// Boundary and charset are set to /// <code>null</code> /// . /// </summary> /// <param name="mode">the desired mode</param> public MultipartEntity(HttpMultipartMode mode) : this(mode, null, null) { }
/// <summary>Creates an instance with the specified settings.</summary> /// <remarks>Creates an instance with the specified settings.</remarks> /// <param name="subType"> /// mime subtype - must not be /// <code>null</code> /// </param> /// <param name="charset"> /// the character set to use. May be /// <code>null</code> /// , in which case /// <see cref="MIME.DefaultCharset">MIME.DefaultCharset</see> /// - i.e. US-ASCII - is used. /// </param> /// <param name="boundary"> /// to use - must not be /// <code>null</code> /// </param> /// <param name="mode">the mode to use</param> /// <exception cref="System.ArgumentException">if charset is null or boundary is null /// </exception> public HttpMultipart(string subType, Encoding charset, string boundary, HttpMultipartMode mode) : base() { if (subType == null) { throw new ArgumentException("Multipart subtype may not be null"); } if (boundary == null) { throw new ArgumentException("Multipart boundary may not be null"); } this.subType = subType; this.charset = charset != null ? charset : MIME.DefaultCharset; this.boundary = boundary; this.parts = new AList<FormBodyPart>(); this.mode = mode; }