BrowserMob not proxying localhost pages - python-2.7

I'm trying to use BrowserMob to proxy pages with Selenium WebDriver. When the (Python) test case tries to load pages from localhost, BrowserMob fails to proxy them.
Is it possible for BrowserMob to proxy connections to the webserver at localhost?

I had the same problem with Selenium ChromeDriver. It didn't use proxy for localhost.
Setting noProxy attribute of seleniumProxy to "<-loopback>" solved the issue.
val seleniumProxy = ClientUtil.createSeleniumProxy(this)
...
seleniumProxy.noProxy = "<-loopback>"
Take a look at below link for details.
https://chromium.googlesource.com/chromium/src/+/master/net/docs/proxy.md#bypass-rule_subtract-implicit-rules

BrowserMob Proxy will work with localhost, but only in the latest version (2.0.0), and only when defining the bmp.allowNativeDnsFallback Java property when running the proxy. I'm not familiar with the Python wrapper, but it's unlikely that it meets those criteria.
The problem is the DNS resolution that BrowserMob Proxy uses, which essentially ignores the hosts file that defines localhost. If you use 127.0.0.1 instead of localhost when making requests it should work for you.

Related

Deploy Django with SSL without Nginx

Is it possible to deploy a django project without using third party tools like nginx or apache just to serve up https:// webpages? Being forced to setup a reverse proxy or some other web server just to serve https seems a bit overkill.
Using of built-in development server (manage.py runserver) is a bad idea for production environment. But, yes you can use SSL connection even with built-in server
Better idea is to use some application server. For example gunicorn. And yes again, you can serve SSL connection with gunicorn.
Apache or Nginx servers are not just for https. These allows you to effectively control other server resources like max number of processes, request/response headers, etc. WEB servers support many features that you can set without writing python code. And that will be more understandable for infra/server engineers.

Hosting Back end Application with API on EC2 instance

I'm quite new to AWS and I have been starting to work with EC2 instances. I have a web application that has a frontend and backend separately. So first I hosted the backend application on EC2 instance and it is a Symfony framework based REST API Application. So I have installed all dependencies and now the application is running. But to check the application I ran some API calls to the application using postman and seems application is not working as intended. I get following response from Postman. I have also provided security group configurations properly.
When I start sysmfony app it says [OK] Server listening on http://127.0.0.1:8000.
Can't figure out why this is happening. Can someone help me here?
You are running your application trough CLI (Symfony web server bundle) , by default this will bind to 127.0.0.1 which can't be accessed from outside. To fix this, you must bind to your server's public IP/hostname and port:
php bin/console server:start 192.168.1.1:8000 # replace with your ip
You can also bind to all your IP addresses using 0.0.0.0
But keep in mind, you should not use built in server for production, it's slow and less secure. Use a real web server instead, like Apache or Nginx.

using socks proxy with postman

We are trying use socks proxy for tunneling the requests through putty. It used to work in browser version of postman, as we it used to pickup chrome's proxy settings.
The standalone version of postman does not support socks proxy, it just accepts a proxy host and port and no parameters for the socks settings. Is there any way to use socks proxy with standlone postman?
Please advice.
The http-proxy-to-socks NodeJS client is suggested in a helpful post in the Github issue tracking Postman app support for SOCKS5 proxy.
If you have Node.js (and NPM) installed, you can install and configure http-proxy-to-socks on your system and then provide the resulting HTTP proxy values in the existing native Postman app HTTP/HTTPS proxy configuration settings.
On macOS, this simple command creates an HTTP proxy forwarding to my SOCKS proxy:
hpts -s 127.0.0.1:7941 -p 7951
In the Postman (v7.1.1 macOS) 'Proxy' section of preferences/settings, enabling the 'Global Proxy Configuration' and entering the '-p' port value from this command (as well as 'localhost') into the 'Proxy Server' inputs was successful for me.
This particular solution requires less alteration of existing settings in Postman than some other posts in that Github issue that suggest alternative workarounds where URLs have to be remapped to a specific localhost port or similar tedious changes.
One other option to use is a tool privoxy.
There is a blog post on how to use it with Postman: https://www.getpagespeed.com/server-setup/beyond-privoxy
In short, set the forwarding for a domain, where 127.0.0.1:8023 is the SOCKS proxy of yours. This can be done by adding the following line to /etc/privoxy/config.
forward-socks5 .domain.tld 127.0.0.1:8023 .
The default port privoxy listens on is 8118.
Finally configure Postman to use 127.0.0.1:8118 as proxy, i.e., using privoxy which forwards the requests to your SOCKS proxy.

Rails - How can I remove the :3000 from the URL in rails thin server?

I have binded my rails thin server to a local IP. which I have given the domain name as project1. But when I am changing the hostname to project1 sometimes it goes to project1:3000. How can I remove the :3000 from the URL?
Web standards are:
http is port 80.
https is port 443.
When you go to http://stackoverflow.com, it is the same as http://stackoverflow.com:80 or https://www.google.com is the same as https://www.google.com:443
So, the :3000 at the end of the url is the port where your development server is pointing, this is normal behavior for web development. All modern frameworks will serve up the development site on a different port, 3000 being the most common. This is done for a lot of reasons, two good ones are.
Don't need to change any permission to run on port 3000, like you do if you want to run on 80, and you don't need to us an ssl certificate if you run on 443.
You can tell when you are in development.
You are trying to do something you shouldn't. If you haven't used the correct helper methods to build your links in rails you could run into some issue.
Now that you know why you shouldn't do it. You can just change the port in the rails server command like this rails server -b THEIPYOUWANTTOUSE -p 80. You will have to have the correct permissions.
First of all.You need proxy server, because rails have their app server lika thin, puma, rack and you need server that will accept requests to your IP (nginx, apache) and give them to rails server. There is a lot of guides how to deploy rails app in production mode. Try this guide or this one . This will help you run your application in production mode.

Automatic HTTPS on Openshift/AWS/some PaaS

I'm working on a Python project that depends on a package that runs Gunicorn as a web server. I need to support https, but the Gunicorn configuration exposed by the package doesn't allow me to pass in keyfile or certfile options, and 'http' is hard-coded throughout the package.
I was wondering if there's some easy way to get https working transparently between clients and Gunicorn without Gunicorn knowing about it, on OpenShift or any popular PaaS.
Take a look at the solution purposed this Openshift KB https://www.openshift.com/kb/kb-e1044-how-to-redirect-traffic-to-https
OpenShift Online apparently handles this automatically by default.
Just change the http to https in the application url they give you (https://xxx-yyy.rhcloud.com) and you've got TLS using their *.rhcloud.com certificate.
I was expecting more configuration and just needed somebody to tell me "just change the url to https".