0

I need something quite different from question with similar subject.

I'm wondering if exist a .NET library that creates a real http request stream (obviously in parametric way). This is not for ASP.NET or other web framework, I want a raw stream of bytes (not mock objects of various http contexts).

I have intentionally omitted fake from the question title, because I need a real http request but I do not want a component that sent it over the network.

[note by ebohlman]: If I read you correctly, a clearer way of putting it is "... creates a simulated http request stream (at the raw-byte level) based on supplied parameters ..."

Basically I should be able to (it follows pseudo-C#):

[Fact]
void Parse_http_request_headers() {
  HttpRequest req = HttpRequestBuilder.Create(HttpMethod.Get, "http://someserver/app/etc/etc");

  HttpParser parser = new HttpParser(req.ToByteArray());

  parser.Method.Should().Be("GET");
  parser.Scheme.Should().Be("http");
  // Remainder omitted
}

I just want to know if someone already created something like this.

2
  • I need to write a strong http protocol implementation, hence primarly an (error free) http parser. Commented Jan 29, 2013 at 15:52
  • @ebohlman, agree with your editing. In fact I'm try to get exactly this result. If anyone suggests something already done, I'll publish a first draft on github, when done. (And a link here for reference). Commented Jan 30, 2013 at 18:38

1 Answer 1

1

One way to do this would be to create a program that uses TcpListener to capture and save the request stream. Run it on your local computer.

Then, in a separate program, create a regular HttpWebRequest and send it to the program that's listening. The listener saves the stream to a binary file, and you now have a request stream that you can examine.

Sign up to request clarification or add additional context in comments.

2 Comments

Mimschel, I've evaluated this option before posting the question. From some initial investigation, it seems uncomfortable in automated test scenario. In fact this is why I say 'I do not want ... sent over the network'. Maybe I was not precise, but 'localhost <-> localhost' was included. Anyway, thank for replying with precise description (+1).
As promised I can finally share my work that do exactly what I needed: github.com/gsscoder/surfhttp. Just please take into account that this is an alfa of a work in progress.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.