public void BuilderSetsRequestBodyFactory() { Configuration.HttpContentFactory f = () => new StringContent("x"); var b = Configuration.Builder(uri).RequestBodyFactory(f); Assert.Same(f, b.Build().RequestBodyFactory); }
public async Task HTTP_request_body_can_be_specified() { var handler = new StubMessageHandler(); handler.QueueStringResponse(":"); HttpContent content = new StringContent("{}"); Configuration.HttpContentFactory contentFn = () => { return(content); }; var evt = new EventSource(new Configuration(_uri, handler, readTimeout: _defaultReadTimeout, method: HttpMethod.Post, requestBodyFactory: contentFn)); evt.CommentReceived += (_, e) => { evt.Close(); }; await evt.StartAsync(); var request = handler.GetRequests().First(); Assert.Equal(content, request.Content); }
public async Task HTTP_request_body_can_be_specified() { var handler = new StubMessageHandler(); handler.QueueResponse(StubResponse.StartStream()); HttpContent content = new StringContent("{}"); Configuration.HttpContentFactory contentFn = () => { return(content); }; var config = new ConfigurationBuilder(_uri).MessageHandler(handler) .Method(HttpMethod.Post).RequestBodyFactory(contentFn).Build(); var evt = new EventSource(config); handler.RequestReceived += (s, r) => evt.Close(); await evt.StartAsync(); var request = handler.GetRequests().First(); Assert.Equal(content, request.Content); }
/// <summary> /// Sets a factory for HTTP request body content, if the HTTP method is one that allows a request body. /// </summary> /// <remarks> /// This is in the form of a factory function because the request may need to be sent more than once. /// </remarks> /// <param name="factory">the factory function, or null for none</param> /// <returns>the builder</returns> public ConfigurationBuilder RequestBodyFactory(Configuration.HttpContentFactory factory) { this._requestBodyFactory = factory; return(this); }