How to figure out if the request coming to envoy (load balancer) is from a real user or google bot? - load-balancing

In our team we use envoyproxy (v1.18) as load balancer to handle requests (btw I'm a newbie in using envoy). Now I want to see if the request that reaches envoy, is coming from a real user or it's from a google bot. As I read in the official documentation, in each request's header, there is something called "user-agent" that adds something into the request header which can be used for this purpose but I don't exactly know how to use it. And also I'm not sure whether that's the best way to do it. I'd appreciate if anyone could guide me on this.

Related

How to receive XMLHTTPRequests on Server side?

it's probably I pretty dumb question but I just can't find any information online on how to do this. Probably I'm googling the wrong stuff.
I have to do 2 things. Send xml files via XMLHTTPRequests to a given Server. That's not a problem and easily done. But the company I'm working with also wants me to provide a Server that can receive XMLHTTPRequests and saves them into a file which I can then work with.
How do I handle this? Does I have to setup e.g. NGINX to do this or is this just a specific website I have to host? When I google for XMLHTTPRequests I only find how to send or get data but not how to setup the Server Side. I really have no clue.
Hope you can send me the right way so I can finally continue to work on this.
ty :)
You need a web server server side to receive requests from XMLHTTPRequest calls. You could set up NGINX to do this, or use any web server that you want.
This isn't usually covered in the documentation because you need to serve the page that contains the JavaScript with the XMLHTTPRequest from some server. To get to the point where you are making a XMLHTTPRequest, you already need some HTTP server set up and working. You would usually configure the page to be served from some a main URL like https://example.com/ and have the XMLHTTPRequest call to another URL like https://example.com/log-data would have you logic for storing to a file like your requirement.

Instagram realtime api https

I'm coding an app in PHP and I've had issues starting a tag subscription when I don't use HTTPS, I've tested both ways and would prefer to use HTTP if possible.
Has anyone else run into this and know of a solution?
Their documentation doesn't show the need for https. When I use HTTP I get the error
Unable to reach callback URL "http://...
My issue wasn't https vs http. It was my function that curls the post data. I rebuilt it and it works now.
A note for future people trying to use the Realtime API it returns zero data about the Instagram post which I find odd, why note include a post id at the very least. All it currently does is ping your server with data about your subscription effected. Its also worth noting to see that data you have to use this command in PHP
$igdata = file_get_contents("php://input");

API subdomain - what should be done with the root?

Let's say I have a subdomain that I use for my site's API: http://api.example.com/
All of the API's methods are accessible as URL segments such as http://api.example.com/some_method, so the root itself isn't used for anything.
Should it redirect to http://example.com/, redirect to a 404 page like Twitter, emit a basic response in the format of the API with a short message, or just have it send an empty response?
Are there any resources out there (articles, etc.) with any other possible suggestions?
I think that's up to you. In a RESTful API, the root would be the starting point for visitors to learn how to operate your system (HATEOAS). But since you talk about /some-method, you're probably not using the REST architectural style, so that's not applicable.
I would avoid the empty response. Maybe a short message pointing to documentation for the API? It really depends a lot on how the rest of your system is designed, so it's hard to give "correct" advice.

Rails: Detecting bot IPs to get around shortener pings

I have an application that logs clicks by users. The problem is, these clicks are being pushed through Twitter, which shortens every single link with t.co. Because of this, Twitter appears to hit the link between 7-15 times from different IPs, probably to do things like logging and SPAM protection. The issue is that this logs 7-15 "clicks" on my app that didn't come from actual users.
I am wondering if there is a way to detect if a visit is coming from an actual user or is simply being cURL'd or something of the sort from a bot or spider.
The one method that seemed it could have worked was using http://www.projecthoneypot.org/ 's API to see if the IPs hitting my site are coming from known bots. I found a gem to help (http://cl.ly/GlT8) but kept getting a NET DNS error while trying to use it.
I am fresh out of ideas. Would really appreciate any assistance!
Twitter should set its User-Agent: http header properly so you can filter those out. This can be forged of course but it's a start.
You can obtain the header in rails with request.headers["User-Agent"].

Dropbox api: Can someone provide a HTTP request example?

Could someone show me an example or a starting point on how Dropbox api http requests should look?
For example if I want to receive tokens how would the HTTP/1.1 request look like for this?
I'm planning on writing a program in C using sockets,
write(sockfd,buffer,strlen(buffer));
What should buffer look like to receive security tokens from dropbox? I hope I'm making sense.
The official SDKs on the Dropbox developer site each include working examples that you can work from:
https://www.dropbox.com/developers/reference/sdk