Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intercept HTTP headers #1

Open
imclint21 opened this issue Jul 19, 2019 · 6 comments
Open

Intercept HTTP headers #1

imclint21 opened this issue Jul 19, 2019 · 6 comments

Comments

@imclint21
Copy link

Hi,,

I would like to intercept HTTP headers and response, can you said me how to achieve this ?

Thanks you

@Falanwe
Copy link
Member

Falanwe commented Jul 19, 2019

Hi,

this proxy is not really the right tool to do that: when used as a TCP proxy, it just forwards the content of the TCP connection to the remote endpoint without reading it. To intercept HTTP headers, you would need to parse this content.

It's likely there are products out there that already do what you want. What's your use case, and where do you need to run it?

@imclint21
Copy link
Author

Yes yes you right, but I want to do this for a project :D

I tried to do this, but I don't know why it don't works, I'm not very good with Async and Wait programming in C# :/

I explain you what I want to do, I would like to make a TCP proxy that redirect flow depending on user, so I need to parse Authorization header, getting user, and with this user redirecting to the good IP :)

@imclint21
Copy link
Author

Do you have a telegram/discord/skype or something else @Falanwe ?

@hudsonventura
Copy link

@clintnetwork did you manage to get the headers? O want to do something like that.
Whenever I read data from the socket, the app erases the socket data and does not forward it to the output.

@hudsonventura
Copy link

@clintnetwork maybe you'll like the line 162 of https://github.com/microsoft/referencesource/blob/master/mscorlib/system/io/stream.cs

Code:
private async Task CopyToAsyncInternal(Stream source, Stream destination)
{
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = await source.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false)) != 0)
{
Console.WriteLine(Encoding.ASCII.GetString(buffer, 0, bytesRead));
await destination.WriteAsync(buffer, 0, bytesRead).ConfigureAwait(false);
}
}

@jmderuty
Copy link
Member

Sorry, it has been some time.

The project was developed on our side because we needed something very simple for both TCP and UDP:

  • We needed to support ipv6 trafic to a server that only had ipv4
  • We needed to forward trafic from a game with hardcoded ip addresses to another server.

Both these requirements don't require modifying the headers even if I agree that it would be very useful in the general case, for HTTP requests.

The proxy currently doesn't try to understand protocols, which is actually very useful if you are not forwarding HTTP trafic and we probably want the TCP forwarder this way.

To read and modify headers, the best option is probably to add a new forwarder type configurable in config, specifically for HTTP, using kestrel as a webserver to parse the requests and then forward them. It would enable scenarios like HTTPS to HTTP forwarding or even simple loadbalancing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants