Request Routing Server

Is there any way to differentiate and route the requests that comes from the browser and from the command line?

Eg: My LoadServer(running on the port 80) will get two kinds of requests from the browser and from the command line and in the backend, two more RequestServers are running on port 8081 and 8082. if a command line request is received to my LoadServer:80 it should redirect to RequestServer:8081 and if the browser request then RequestServer:8082.

Thanks in Advance.

Maybe you can use request´s headers. The Web Browser would fill additional information that you could be not found in the command line request.

Perhaps on the user agent, but this is very old school…

In my opinion, if you have different servers with different purposes, make them available separately, such that each consumer can connect its own dedicated server.

1 Like

Hi @NobbZ,

Both will be available separately but for users easiness I’m using another server(third one) which routes the requests based on the requests.

Hi @Yamil_Bracho

What Kind of additional Information I’m seeing the same information only the User Agent is changing that too for Command line is showing CURL/…/… if you are saying the same can you tell me the generic method of differentiating all kinds of browsers with different versions and Command Line(CURL) versions

As a user I’d be confused if curl gave me different results than what I see in my browser…

Also, some headless scripting of chrome or firefox, do you consider that “from the terminal”? What is about lynx, links or brow.sh? How would you treat those? Someone trying to scrape your page using a programming language, is that “from the terminal” or “from a browser”?

The simplest thing for you and your users, is to simply make different resources available under different URLs.

@NobbZ

In detail I’m running a Git Server(Golang) and Repository Viewing Server(Java). My application chould exactly run like https://android.googlesource.com/.

Actually it will be very easy if both are in same language but i developed in golang and the Gitiles is in Java.So I planned to run one more in different port which routes requests.

Sorry, I have no clue how this is related to the problem you describe. It just seems to be different services to me…

You can use this list (https://en.wikipedia.org/wiki/List_of_HTTP_header_fields).
There would be some keys or differents values for existing key from a browser and from a custom request.

Inside a handler you might do something like this to change behavior:

userAgent := req.Header.Get("user-agent")
baseUA := strings.Split(userAgent, "/")[0]
if baseUA == "curl" {
	fmt.Println("doing command line stuff")
} else {
	fmt.Println("doing browser stuff")
}

That might work unless your CLI users are setting their own user-agent in curl!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.