public void TestSimpleQueryString() { HttpInput result = HttpHelper.ParseQueryString("key1=value1&key2=value2"); Assert.Equal("value1", result["key1"].Value); Assert.Equal("value2", result["key2"].Value); }
public void TestMultipleLevels() { HttpInput parent = new HttpInput("test"); parent.Add("user[extension][id]", "1"); Assert.Equal("1", parent["user"]["extension"]["id"].Value); }
public void TestSimple() { HttpInput input = new HttpInput("teest"); input.Add("ivrMenu", "myName"); Assert.Equal("myName", input["ivrMenu"].Value); }
public void Test() { UrlDecoder decoder = new UrlDecoder(); Assert.True(decoder.CanParse("application/x-www-form-urlencoded")); Assert.False(decoder.CanParse("text/plain")); Assert.False(decoder.CanParse(string.Empty)); Assert.False(decoder.CanParse(null)); MemoryStream stream = new MemoryStream(); string value = @"user[firstname]=jonas&user[extension][id]=1&myname=jonas&user[firstname]=arne"; // it's always VALUES and not the complete string that should be encoded. //string urlencoded = HttpUtility.UrlEncode(@"user[firstname]=jonas&user[extension][id]=1&myname=jonas&user[firstname]=arne"); byte[] bytes = Encoding.ASCII.GetBytes(value); stream.Write(bytes, 0, bytes.Length); stream.Seek(0, SeekOrigin.Begin); HttpInput input = decoder.Decode(stream, "application/x-www-form-urlencoded", Encoding.ASCII); Assert.Equal("jonas", input["myname"].Value); Assert.Equal(2, input["user"]["firstname"].Count); Assert.Equal("jonas", input["user"]["firstname"].Values[0]); Assert.Equal("arne", input["user"]["firstname"].Values[1]); Assert.Equal("1", input["user"]["extension"]["id"].Value); Assert.Null(input["unknow"].Value); Assert.Equal(HttpInputItem.Empty, input["unknown"]); }
//internal EventTraceActivity EventTraceActivity //{ // get // { // return this.eventTraceActivity; // } //} // Note: This method will return null in the case where throwOnError is false, and a non-fatal error occurs. // Please exercise caution when passing in throwOnError = false. This should basically only be done in error // code paths, or code paths where there is very good reason that you would not want this method to throw. // When passing in throwOnError = false, please handle the case where this method returns null. public HttpInput GetHttpInput(bool throwOnError) { HttpInput httpInput = null; if (throwOnError || !_errorGettingHttpInput) { try { httpInput = GetHttpInput(); _errorGettingHttpInput = false; } catch (Exception e) { _errorGettingHttpInput = true; if (throwOnError || Fx.IsFatal(e)) { throw; } DiagnosticUtility.TraceHandledException(e, TraceEventType.Warning); } } return(httpInput); }
/// <summary> /// Parses a query string. /// </summary> /// <param name="queryString">Query string (URI encoded)</param> /// <param name="contentEncoding">Content encoding</param> /// <returns>A <see cref="HttpInput"/> object if successful; otherwise <see cref="HttpInput.Empty"/></returns> /// <exception cref="ArgumentNullException"><c>queryString</c> is <c>null</c>.</exception> /// <exception cref="FormatException">If string cannot be parsed.</exception> public static HttpInput ParseQueryString(string queryString, Encoding contentEncoding) { if (queryString == null) throw new ArgumentNullException("queryString"); if (queryString == string.Empty) return HttpInput.Empty; HttpInput input = new HttpInput("QueryString"); queryString = queryString.TrimStart('?', '&'); // a simple value. /* if (queryString.IndexOf("&") == -1 && !queryString.Contains("%3d") && !queryString.Contains("%3D") && !queryString.Contains("=")) { input.Add(string.Empty, queryString); return input; }*/ if (queryString.IndexOf("&") == -1 && !queryString.Contains("=")) { input.Add(string.Empty, queryString); return input; } int state = 0; int startpos = 0; string name = null; for (int i = 0; i < queryString.Length; ++i) { int newIndexPos; if (state == 0 && IsEqual(queryString, ref i, out newIndexPos)) { name = queryString.Substring(startpos, i - startpos); i = newIndexPos; startpos = i + 1; ++state; } else if (state == 1 && IsAmp(queryString, ref i, out newIndexPos)) { Add(input, name, queryString.Substring(startpos, i - startpos), contentEncoding); i = newIndexPos; startpos = i + 1; state = 0; name = null; } } if (state == 0 && !input.GetEnumerator().MoveNext()) throw new FormatException("Not a valid query string: " + queryString); if (startpos <= queryString.Length) { if (name != null) Add(input, name, queryString.Substring(startpos, queryString.Length - startpos), contentEncoding); else Add(input, string.Empty, queryString.Substring(startpos, queryString.Length - startpos), contentEncoding); } return input; }
public void TestWithAmpInString() { HttpInput result = HttpHelper.ParseQueryString("key1=hello%26goodbye&key2=value2"); Assert.Equal("hello&goodbye", result["key1"].Value); Assert.Equal("value2", result["key2"].Value); }
public void TestLarge() { string url = "ivrMenu[Name]=Huvudmeny&ivrMenu[ExtensionId]=6&ivrMenu[OpenPhraseId]=267&ivrMenu[ScheduleId]=1&ivrMenu[ClosePhraseId]=268&ivrMenu[CloseActionId]=3&ivrMenu[CloseActionValue]=26&ivrMenu[TimeoutPhraseId]=267&ivrMenu[TimeoutActionId]=&ivrMenu[TimeoutActionValue]=&ivrMenu[TimeoutSeconds]=10&ivrMenu[Digits][1][Digit]=1&ivrMenu[Digits][1][ActionId]=1&ivrMenu[Digits][1][ActionValue]=49&ivrMenu[Digits][2][Digit]=2&ivrMenu[Digits][2][ActionId]=&ivrMenu[Digits][2][ActionValue]=&ivrMenu[Digits][3][Digit]=3&ivrMenu[Digits][3][ActionId]=&ivrMenu[Digits][3][ActionValue]=&ivrMenu[Digits][4][Digit]=4&ivrMenu[Digits][4][ActionId]=&ivrMenu[Digits][4][ActionValue]=&ivrMenu[Digits][5][Digit]=5&ivrMenu[Digits][5][ActionId]=&ivrMenu[Digits][5][ActionValue]=&ivrMenu[Digits][6][Digit]=6&ivrMenu[Digits][6][ActionId]=&ivrMenu[Digits][6][ActionValue]=&ivrMenu[Digits][7][Digit]=7&ivrMenu[Digits][7][ActionId]=&ivrMenu[Digits][7][ActionValue]=&ivrMenu[Digits][8][Digit]=8&ivrMenu[Digits][8][ActionId]=&ivrMenu[Digits][8][ActionValue]=&ivrMenu[Digits][9][Digit]=9&ivrMenu[Digits][9][ActionId]=&ivrMenu[Digits][9][ActionValue]=&ivrMenu[Digits][0][ActionId]=&ivrMenu[Digits][0][ActionValue]=&ivrMenu[Digits][*][ActionId]=&ivrMenu[Digits][*][ActionValue]=&ivrMenu[Digits][#][ActionId]=&ivrMenu[Digits][#][ActionValue]="; UrlDecoder decoder = new UrlDecoder(); Assert.True(decoder.CanParse("application/x-www-form-urlencoded")); Assert.False(decoder.CanParse("text/plain")); Assert.False(decoder.CanParse(string.Empty)); Assert.False(decoder.CanParse(null)); MemoryStream stream = new MemoryStream(); //string urlencoded = HttpUtility.UrlEncode(url); byte[] bytes = Encoding.ASCII.GetBytes(url); stream.Write(bytes, 0, bytes.Length); stream.Seek(0, SeekOrigin.Begin); HttpInput input = decoder.Decode(stream, "application/x-www-form-urlencoded", Encoding.ASCII); Assert.Equal("Huvudmeny", input["ivrMenu"]["Name"].Value); Assert.Equal("6", input["ivrMenu"]["ExtensionId"].Value); Assert.Equal("267", input["ivrMenu"]["OpenPhraseId"].Value); Assert.Equal("1", input["ivrMenu"]["Digits"]["1"]["Digit"].Value); Assert.Equal("1", input["ivrMenu"]["Digits"]["1"]["ActionId"].Value); Assert.Equal("49", input["ivrMenu"]["Digits"]["1"]["ActionValue"].Value); }
internal async Task HandleRequest(HttpContext context) { if (ChannelDispatcher == null) { // TODO: Look for existing SR which would work here. Cleanup how the exception is thrown. throw new InvalidOperationException("Channel Dispatcher can't be null"); } var requestContext = HttpRequestContext.CreateContext(_httpSettings, context); HttpInput httpInput = requestContext.GetHttpInput(true); (Message requestMessage, Exception requestException) = await httpInput.ParseIncomingMessageAsync(); if ((requestMessage == null) && (requestException == null)) { throw Fx.Exception.AsError( new ProtocolException( SR.MessageXmlProtocolError, new XmlException(SR.MessageIsEmpty))); } requestContext.SetMessage(requestMessage, requestException); if (requestMessage != null) { requestMessage.Properties.Add("Microsoft.AspNetCore.Http.HttpContext", context); } await ChannelDispatcher.DispatchAsync(requestContext); await requestContext.ReplySent; }
public void TestPairAndSimpleValue() { HttpInput result = HttpHelper.ParseQueryString("a=2&key1"); Assert.Equal("2", result["a"].Value); Assert.Equal("key1", result[string.Empty].Value); }
public IObserver <T> CreateObserver <T>(T dummy, HttpInput input) { return(Observer.Create <T>(t => { this.PostMessageAsync(input, t).ToBackGround(); })); }
public Task Send( [FromBody] HttpInput input) { var send = _mahuaCenter.HandleMahuaInput(input); return(send); }
/// <summary> /// Creates a resource representing an HTTP server providing the input files. For alternative input /// methods see list of supported input and output storages /// (https://bitmovin.com/docs/encoding/articles/supported-input-output-storages)<para /> /// /// For reasons of simplicity, a new input resource is created on each execution of this /// example. In production use, this method should be replaced by a get call to retrieve an existing resource. /// (https://bitmovin.com/docs/encoding/api-reference/sections/inputs#/Encoding/GetEncodingInputsHttpByInputId) /// <para /> /// API endpoint: /// https://bitmovin.com/docs/encoding/api-reference/sections/inputs#/Encoding/PostEncodingInputsHttp /// </summary> /// <param name="host">The hostname or IP address of the HTTP server e.g.: my-storage.biz</param> private Task <HttpInput> CreateHttpInput(string host) { var input = new HttpInput() { Host = host }; return(_bitmovinApi.Encoding.Inputs.Http.CreateAsync(input)); }
public void TestAgain() { HttpInput parent = new HttpInput("test"); parent.Add("interception[code]", "2"); Assert.Equal("2", parent["interception"]["code"].Value); parent.Add("theid", "2"); Assert.Equal("2", parent["theid"].Value); parent.Add("interception[totime]", "1200"); Assert.Equal("1200", parent["interception"]["totime"].Value); }
public string GetLastPoint(HttpInput hi) { hi.Url = string.Format("http://{0}/login_biz/query_money.oko?uid=01161add5a3c4c55bd9c133baa9effd0", ip); var ho = HttpManager.Instance.ProcessRequest(hi); if (ho.IsOK) { return(ho.TxtData.Replace("remain money:", "")); } return(string.Empty); }
public void Test() { HttpInput input = new HttpInput("teest"); input.Add("ivrMenu", string.Empty); input.Add("ivrMenu[Digits][1][Digit]", "1"); input.Add("ivrMenu[Digits][1][Action]", "2"); input.Add("ivrMenu[Digits][1][Value]", string.Empty); Assert.Equal("1", input["ivrMenu"]["Digits"]["1"]["Digit"].Value); Assert.Equal("2", input["ivrMenu"]["Digits"]["1"]["Action"].Value); Assert.Equal(string.Empty, input["ivrMenu"]["Digits"]["1"]["Value"].Value); }
private static void TestToString() { string queryString = "title=hello&firstname=jonas&status=super"; HttpInput input = HttpHelper.ParseQueryString(queryString, System.Text.Encoding.UTF8); Assert.Equal(queryString, input.ToString(true)); queryString = "title[jonas]=hello&title[arne]=ohno&firstname=jonas&status=super"; input = HttpHelper.ParseQueryString(queryString, System.Text.Encoding.UTF8); Assert.Equal(queryString, input.ToString(true)); }
public static void put_watcher_sample(ElasticClient client) { // action var action = new LoggingAction("mylog") { Text = "some node is down", Level = LogLevel.Info }; ConditionContainer condition = new AlwaysCondition(); var my_http = new HttpInputRequest { Host = "localhost", Port = 9200, Path = "_cat/nodes", Method = HttpInputMethod.Get }; var input = new HttpInput { Request = my_http }; var hourly = new HourlySchedule(); int[] intNumbers = new int[] { 30 }; hourly.Minute = intNumbers; var trigger = new ScheduleContainer { Hourly = hourly }; var id = "status-check"; PutWatchRequest watchRequest = new PutWatchRequest(id) { Actions = action, Condition = condition, Input = input, Trigger = trigger }; PutWatchResponse response = client.Watcher.Put(watchRequest); Console.WriteLine("hello"); }
public Stream GetInputStream() { try { // CSDMain #133228: "Consume GetBufferlessInputStream" // The ReadEntityBodyMode property on the HttpRequest keeps track of whether the request stream has already been accessed, and if so, what API was used to access the request. // - "None" means that the request stream hasn't been accessed. // - "Bufferless" means that GetBufferlessInputStream() was used to access it. // - "Buffered" means GetBufferedInputStream() was used to access it. // - "Classic" means that either the InputStream, Form, Files, or BinaryRead APIs were invoked already. // In general, these values are incompatible with one another, meaning that once the request was accessed in a "Classic" way, only "Classic" APIs can be invoked on the HttpRequest. // If incompatible APIs are invoked, an HttpException is thrown. // In order to prevent HttpExceptions from being thrown for this reason, we will check the ReadEntityBodyMode, and access the request stream with the corresponding API // If the request stream hasn't been accessed yet (eg, by an HttpModule which executed earlier), then we will use GetBufferlessInputStream by default. ReadEntityBodyMode mode = this.context.Request.ReadEntityBodyMode; Fx.Assert(mode == ReadEntityBodyMode.None || mode == ReadEntityBodyMode.Bufferless || mode == ReadEntityBodyMode.Buffered || mode == ReadEntityBodyMode.Classic, "Unknown value for System.Web.ReadEntityBodyMode enum"); if (mode == ReadEntityBodyMode.None && ServiceHostingEnvironment.AspNetCompatibilityEnabled && AppSettings.UseClassicReadEntityMode) { mode = ReadEntityBodyMode.Classic; } switch (mode) { case ReadEntityBodyMode.None: case ReadEntityBodyMode.Bufferless: return(this.context.Request.GetBufferlessInputStream(true)); // ignores system.web/httpRuntime/maxRequestLength case ReadEntityBodyMode.Buffered: return(this.context.Request.GetBufferedInputStream()); default: // ReadEntityBodyMode.Classic: return(this.context.Request.InputStream); } } catch (HttpException hostedException) { if (hostedException.WebEventCode == WebEventCodes.RuntimeErrorPostTooLarge) { throw FxTrace.Exception.AsError(HttpInput.CreateHttpProtocolException(SR.Hosting_MaxRequestLengthExceeded, HttpStatusCode.RequestEntityTooLarge, null, hostedException)); } else { throw FxTrace.Exception.AsError(new CommunicationException(hostedException.Message, hostedException)); } } }
public Task CQ_getLoginNick([FromBody] CqpCQ_getLoginNickHttpInput input) { var httpInput = new HttpInput { TypeCode = nameof(CQ_getLoginNick), MahuaPlatform = MahuaPlatform.Cqp, Data = new ReadOnlyDictionary <string, object>(new Dictionary <string, object> { } ) } ; return(_mahuaCenter.HandleMahuaInput(httpInput)); }
public async Task <bool> PostMessageAsync(HttpInput input, string json) { var content = new JsonContent(json); try { var response = await _client.PostAsync(input.LoggingUrl, content); return(response.IsSuccessStatusCode); } catch (Exception e) { return(false); } }
public Task Api_Getbkn([FromBody] QQLightApi_GetbknHttpInput input) { var httpInput = new HttpInput { TypeCode = nameof(Api_Getbkn), MahuaPlatform = MahuaPlatform.QQLight, Data = new ReadOnlyDictionary <string, object>(new Dictionary <string, object> { } ) } ; return(_mahuaCenter.HandleMahuaInput(httpInput)); }
public Task CQ_deleteMsg([FromBody] CqpCQ_deleteMsgHttpInput input) { var httpInput = new HttpInput { TypeCode = nameof(CQ_deleteMsg), MahuaPlatform = MahuaPlatform.Cqp, Data = new ReadOnlyDictionary <string, object>(new Dictionary <string, object> { { nameof(input.MsgId), input.MsgId }, } ) } ; return(_mahuaCenter.HandleMahuaInput(httpInput)); }
public Task Api_DeleteFriend([FromBody] QQLightApi_DeleteFriendHttpInput input) { var httpInput = new HttpInput { TypeCode = nameof(Api_DeleteFriend), MahuaPlatform = MahuaPlatform.QQLight, Data = new ReadOnlyDictionary <string, object>(new Dictionary <string, object> { { nameof(input.好友QQ), input.好友QQ }, } ) } ; return(_mahuaCenter.HandleMahuaInput(httpInput)); }
// Wraps HttpException as inner exception in CommunicationException or ProtocolException (which derives from CommunicationException) static Exception CreateCommunicationException(HttpException hostedException) { if (hostedException.WebEventCode == WebEventCodes.RuntimeErrorPostTooLarge) { // This HttpException is thrown if greater than httpRuntime/maxRequestLength bytes have been read from the stream. // Note that this code path can only be hit when GetBufferedInputStream() is called in HostedHttpRequestAsyncResult.GetInputStream(), which only // happens when an Http Module which is executed before the WCF Http Handler has accessed the request stream via GetBufferedInputStream(). // This is the only case that throws because GetBufferlessInputStream(true) ignores maxRequestLength, and InputStream property throws when invoked, not when stream is read. return(HttpInput.CreateHttpProtocolException(SR.Hosting_MaxRequestLengthExceeded, HttpStatusCode.RequestEntityTooLarge, null, hostedException)); } else { // This HttpException is thrown if client disconnects and a read operation is invoked on the stream. return(new CommunicationException(hostedException.Message, hostedException)); } }
public Task CQ_getCookiesV2([FromBody] CqpCQ_getCookiesV2HttpInput input) { var httpInput = new HttpInput { TypeCode = nameof(CQ_getCookiesV2), MahuaPlatform = MahuaPlatform.Cqp, Data = new ReadOnlyDictionary <string, object>(new Dictionary <string, object> { { nameof(input.domain), input.domain }, } ) } ; return(_mahuaCenter.HandleMahuaInput(httpInput)); }
public Task CQ_setDiscussLeave([FromBody] CqpCQ_setDiscussLeaveHttpInput input) { var httpInput = new HttpInput { TypeCode = nameof(CQ_setDiscussLeave), MahuaPlatform = MahuaPlatform.Cqp, Data = new ReadOnlyDictionary <string, object>(new Dictionary <string, object> { { nameof(input.讨论组号), input.讨论组号 }, } ) } ; return(_mahuaCenter.HandleMahuaInput(httpInput)); }
public Task Api_RemoveGroup([FromBody] QQLightApi_RemoveGroupHttpInput input) { var httpInput = new HttpInput { TypeCode = nameof(Api_RemoveGroup), MahuaPlatform = MahuaPlatform.QQLight, Data = new ReadOnlyDictionary <string, object>(new Dictionary <string, object> { { nameof(input.群号), input.群号 }, } ) } ; return(_mahuaCenter.HandleMahuaInput(httpInput)); }
public Task CQ_getFriendList([FromBody] CqpCQ_getFriendListHttpInput input) { var httpInput = new HttpInput { TypeCode = nameof(CQ_getFriendList), MahuaPlatform = MahuaPlatform.Cqp, Data = new ReadOnlyDictionary <string, object>(new Dictionary <string, object> { { nameof(input.reserved), input.reserved }, } ) } ; return(_mahuaCenter.HandleMahuaInput(httpInput)); }
public Task Api_SetSignature([FromBody] QQLightApi_SetSignatureHttpInput input) { var httpInput = new HttpInput { TypeCode = nameof(Api_SetSignature), MahuaPlatform = MahuaPlatform.QQLight, Data = new ReadOnlyDictionary <string, object>(new Dictionary <string, object> { { nameof(input.个性签名), input.个性签名 }, } ) } ; return(_mahuaCenter.HandleMahuaInput(httpInput)); }
public Task CQ_setGroupAnonymous([FromBody] CqpCQ_setGroupAnonymousHttpInput input) { var httpInput = new HttpInput { TypeCode = nameof(CQ_setGroupAnonymous), MahuaPlatform = MahuaPlatform.Cqp, Data = new ReadOnlyDictionary <string, object>(new Dictionary <string, object> { { nameof(input.群号), input.群号 }, { nameof(input.开启匿名), input.开启匿名 }, } ) } ; return(_mahuaCenter.HandleMahuaInput(httpInput)); }
/// <summary> /// Makes a deep copy of the input /// </summary> /// <param name="input">The input to copy</param> public HttpForm(HttpInput input) : base(input) { }
/// <summary> /// Clear everything in the request /// </summary> public void Clear() { //return; _body.Dispose(); _body = new MemoryStream(); _contentLength = 0; _method = string.Empty; _uri = null; _queryString = HttpInput.Empty; _bodyBytesLeft = 0; _headers.Clear(); _connection = ConnectionType.Close; _param.SetForm(HttpInput.Empty); _param.SetQueryString(HttpInput.Empty); IsAjax = false; _form.Clear(); }
/// <summary> /// Clear everything in the request /// </summary> public void Clear() { _body.Dispose(); _body = new MemoryStream(); _contentLength = 0; _method = string.Empty; _uri = HttpHelper.EmptyUri; _queryString = HttpInput.Empty; _bodyBytesLeft = 0; _headers.Clear(); _connection = ConnectionType.Close; IsAjax = false; _form.Clear(); }
public HttpTestRequest() { _queryString = new HttpInput("QueryString"); _form = new HttpForm(); _param = new HttpParam(_form, _queryString); }
/// <summary> /// Parses a querystring. /// </summary> /// <param name="queryString">Querystring (url decoded)</param> /// <returns>A HttpInput object if successful; otherwise HttpInput.Empty</returns> public static HttpInput ParseQueryString(string queryString) { if (queryString == null) throw new ArgumentNullException("queryString"); if (queryString == String.Empty) return HttpInput.Empty; int state = 0; int startpos = 0; string name = null; HttpInput input = new HttpInput("QueryString"); for (int i = 0; i < queryString.Length; ++i) { int newIndexPos; if (state == 0 && IsEqual(queryString, ref i, out newIndexPos)) { name = queryString.Substring(startpos, i - startpos); i = newIndexPos; startpos = i + 1; ++state; } else if (state == 1 && IsAmp(queryString, ref i, out newIndexPos)) { Add(input, name, queryString.Substring(startpos, i - startpos)); i = newIndexPos; startpos = i + 1; state = 0; name = null; } } if (state == 0 && !input.GetEnumerator().MoveNext()) Add(input, queryString, String.Empty); else if (name != null && startpos <= queryString.Length) Add(input, name, queryString.Substring(startpos, queryString.Length - startpos)); return input; }
public async Task<bool> DeleteHttpInputAsync(HttpInput input) { var response = await _client.DeleteAsync(string.Format("inputs/{0}", input.Id)); return response.StatusCode == System.Net.HttpStatusCode.NoContent; }