Skip to content

Intercept HTTP headers #1

Open
Open

Description

@imclint21

Hi,,

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

Thanks you

Activity

  1. Falanwe commented on Jul 19, 2019

    @Falanwe
    Member

    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?

  2. imclint21 commented on Jul 19, 2019

    @imclint21
    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 :)

  3. imclint21 commented on Jul 19, 2019

    @imclint21
    Author

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

  4. hudsonventura commented on Jun 17, 2021

    @hudsonventura

    @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.

  5. hudsonventura commented on Jun 19, 2021

    @hudsonventura

    @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);
    }
    }

  6. jmderuty commented on Jan 25, 2022

    @jmderuty
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions