internal HttpPostRequestDecoder(IHttpDataFactory factory, IHttpRequest request, Encoding encoding) { if (factory is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.factory); } if (request is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.request); } if (encoding is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.encoding); } // Fill default values if (IsMultipartRequest(request)) { _decoder = new HttpPostMultipartRequestDecoder(factory, request, encoding); } else { _decoder = new HttpPostStandardRequestDecoder(factory, request, encoding); } }
public HttpPostRequestEncoder( IHttpDataFactory factory, IHttpRequest request, bool multipart, Encoding charset, EncoderMode encoderMode) { Contract.Requires(request != null); Contract.Requires(factory != null); Contract.Requires(charset != null); this.request = request; this.charset = charset; this.factory = factory; HttpMethod method = request.Method; if (method.Equals(HttpMethod.Trace)) { throw new ErrorDataEncoderException("Cannot create a Encoder if request is a TRACE"); } // Fill default values this.bodyListDatas = new List <IInterfaceHttpData>(); // default mode this.isLastChunk = false; this.isLastChunkSent = false; this.isMultipart = multipart; this.MultipartHttpDatas = new List <IInterfaceHttpData>(); this.encoderMode = encoderMode; if (this.isMultipart) { this.InitDataMultipart(); } }
public HttpPostRequestDecoder(IHttpDataFactory factory, IHttpRequest request, Encoding encoding) { Contract.Requires(factory != null); Contract.Requires(request != null); Contract.Requires(encoding != null); // Fill default values if (IsMultipartRequest(request)) { this.decoder = new HttpPostMultipartRequestDecoder(factory, request, encoding); } else { this.decoder = new HttpPostStandardRequestDecoder(factory, request, encoding); } }
/** * Multipart example */ private static async Task FormpostmultipartAsync( Bootstrap bootstrap, Uri uriFile, IHttpDataFactory factory, IList <HeaderEntry <AsciiString, ICharSequence> > headers, List <IInterfaceHttpData> bodylist) { // XXX /formpostmultipart // Start the connection attempt. IChannel channel = await bootstrap.ConnectAsync(new IPEndPoint(ClientSettings.Host, ClientSettings.Port)); // Prepare the HTTP request. var request = new DefaultHttpRequest(DotNetty.Codecs.Http.HttpVersion.Http11, HttpMethod.Post, uriFile.ToString()); // Use the PostBody encoder HttpPostRequestEncoder bodyRequestEncoder = new HttpPostRequestEncoder(factory, request, true); // true => multipart // it is legal to add directly header or cookie into the request until finalize foreach (var entry in headers) { request.Headers.Set(entry.Key, entry.Value); } // add Form attribute from previous request in formpost() bodyRequestEncoder.SetBodyHttpDatas(bodylist); // finalize request bodyRequestEncoder.FinalizeRequest(); var list = new List <object>(); // send request list.Add(request); // test if request was chunked and if so, finish the write if (bodyRequestEncoder.IsChunked) { list.Add(bodyRequestEncoder); } await channel.WriteAndFlushManyAsync(list); // Now no more use of file representation (and list of HttpData) bodyRequestEncoder.CleanFiles(); // Wait for the server to close the connection. await channel.CloseCompletion; }
public HttpPostStandardRequestDecoder(IHttpDataFactory factory, IHttpRequest request, Encoding charset) { if (request is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.request); } if (charset is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.charset); } if (factory is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.factory); } _bodyListHttpData = new List <IInterfaceHttpData>(); _bodyMapHttpData = new Dictionary <string, List <IInterfaceHttpData> >(StringComparer.OrdinalIgnoreCase); _currentStatus = MultiPartStatus.Notstarted; _discardThreshold = HttpPostRequestDecoder.DefaultDiscardThreshold; _factory = factory; _request = request; _charset = charset; try { if (request is IHttpContent content) { // Offer automatically if the given request is als type of HttpContent // See #1089 _ = Offer(content); } else { ParseBody(); } } catch (Exception exc) { Destroy(); ExceptionDispatchInfo.Capture(exc).Throw(); } }
public HttpPostStandardRequestDecoder(IHttpDataFactory factory, IHttpRequest request, Encoding charset) { Contract.Requires(request != null); Contract.Requires(charset != null); Contract.Requires(factory != null); this.factory = factory; this.request = request; this.charset = charset; if (request is IHttpContent content) { // Offer automatically if the given request is als type of HttpContent // See #1089 this.Offer(content); } else { this.undecodedChunk = Unpooled.Buffer(); this.ParseBody(); } }
/// <summary> /// TBD /// </summary> /// <param name="factory">the factory used to create InterfaceHttpData</param> /// <param name="request">the request to encode</param> /// <param name="multipart">True if the FORM is a ENCTYPE="multipart/form-data"</param> /// <param name="encoderMode">the mode for the encoder to use. See <see cref="EncoderMode"/> for the details.</param> public HttpPostRequestEncoder(IHttpDataFactory factory, IHttpRequest request, bool multipart, EncoderMode encoderMode) { if (request is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.request); } if (factory is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.factory); } if (charset is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.charset); } this.request = request; this.factory = factory; HttpMethod method = request.Method; if (method.Equals(HttpMethod.Trace)) { ThrowHelper.ThrowErrorDataEncoderException_CannotCreate(); } // Fill default values this.bodyListDatas = new List <IInterfaceHttpData>(); // default mode this.isLastChunk = false; this.isLastChunkSent = false; this.isMultipart = multipart; this.MultipartHttpDatas = new List <IInterfaceHttpData>(); this.encoderMode = encoderMode; if (this.isMultipart) { this.InitDataMultipart(); } }
public HttpPostRequestEncoder(IHttpDataFactory factory, IHttpRequest request, bool multipart) : this(factory, request, multipart, HttpConstants.DefaultEncoding, EncoderMode.RFC1738) { }
public HttpPostStandardRequestDecoder(IHttpDataFactory factory, IHttpRequest request) : this(factory, request, HttpConstants.DefaultEncoding) { }
/// <summary> /// TBD /// </summary> /// <param name="factory">the factory used to create InterfaceHttpData</param> /// <param name="request">the request to encode</param> /// <param name="multipart">True if the FORM is a ENCTYPE="multipart/form-data"</param> public HttpPostRequestEncoder(IHttpDataFactory factory, IHttpRequest request, bool multipart) : this(factory, request, multipart, EncoderMode.RFC1738) { }
/** * Standard post without multipart but already support on Factory (memory management) * * @return the list of HttpData object (attribute and file) to be reused on next post */ private static async Task <List <IInterfaceHttpData> > FormpostAsync(Bootstrap bootstrap, Uri uriSimple, FileStream file, IHttpDataFactory factory, IList <HeaderEntry <AsciiString, ICharSequence> > headers) { // XXX /formpost // Start the connection attempt. IChannel channel = await bootstrap.ConnectAsync(new IPEndPoint(ClientSettings.Host, ClientSettings.Port)); // Prepare the HTTP request. IHttpRequest request = new DefaultHttpRequest(DotNetty.Codecs.Http.HttpVersion.Http11, HttpMethod.Post, uriSimple.ToString()); // Use the PostBody encoder HttpPostRequestEncoder bodyRequestEncoder = new HttpPostRequestEncoder(factory, request, false); // false => not multipart // it is legal to add directly header or cookie into the request until finalize foreach (var entry in headers) { request.Headers.Set(entry.Key, entry.Value); } // add Form attribute bodyRequestEncoder.AddBodyAttribute("getform", "POST"); bodyRequestEncoder.AddBodyAttribute("info", "first value"); bodyRequestEncoder.AddBodyAttribute("secondinfo", "secondvalue ���&"); bodyRequestEncoder.AddBodyAttribute("thirdinfo", TextArea); bodyRequestEncoder.AddBodyAttribute("fourthinfo", TextAreaLong); bodyRequestEncoder.AddBodyFileUpload("myfile", file, "application/x-zip-compressed", false); // finalize request request = bodyRequestEncoder.FinalizeRequest(); // Create the bodylist to be reused on the last version with Multipart support var bodylist = bodyRequestEncoder.GetBodyListAttributes(); var list = new List <object>(); // send request list.Add(request); // test if request was chunked and if so, finish the write if (bodyRequestEncoder.IsChunked) { // could do either request.isChunked() // either do it through ChunkedWriteHandler list.Add(bodyRequestEncoder); } await channel.WriteAndFlushManyAsync(list); // Do not clear here since we will reuse the InterfaceHttpData on the next request // for the example (limit action on client side). Take this as a broadcast of the same // request on both Post actions. // // On standard program, it is clearly recommended to clean all files after each request // bodyRequestEncoder.cleanFiles(); // Wait for the server to close the connection. await channel.CloseCompletion; return(bodylist); }