Skip to content

Commit

Permalink
Fix basic authentication for browsers (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
jthomperoo authored Dec 4, 2023
1 parent 854bb42 commit 02bb599
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Fixed issue with incorrect headers and response code for browser/system level proxy settings
([#1](https://github.com/jthomperoo/simple-proxy/issues/1)).

## [v1.1.0] - 2022-04-08
## Added
### Added
- Basic auth support, can provide `--basic-auth 'username:password'` which the proxy then checks for valid auth
provided in the `Proxy-Authentication` header.
- Can choose if auth should be logged with the `--log-auth` option.
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,23 @@ Usage of simple-proxy:
comma-separated list of pattern=N settings for file-filtered logging
```
## Checking the proxy is working
You can use [cURL](https://curl.se/) on Linux/MacOS systems to check if your proxy is working:
```bash
curl --proxy 'http://localhost:8888' 'https://www.random.org/integers/?num=1&min=1&max=5&col=1&base=10&format=plain&rnd=new'
```
This will reach out to [random.org](https://www.random.org) to fetch a random number, using the default proxy address
and port.
On Windows you can use:
```powershell
curl.exe 'https://www.random.org/integers/?num=1&min=1&max=5&col=1&base=10&format=plain&rnd=new' --proxy 'http://localhost:8888'
```
## Contributing
See the [CONTRIBUTING](./CONTRIBUTING.md) and [CODE OF CONDUCT](./CODE_OF_CONDUCT.md) documents.
3 changes: 2 additions & 1 deletion proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ func (p *ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} else {
glog.Errorln("Unauthorized")
}
http.Error(w, "Unauthorized", http.StatusUnauthorized)
w.Header().Set("Proxy-Authenticate", "Basic")
http.Error(w, "Unauthorized", http.StatusProxyAuthRequired)
return
}
}
Expand Down

0 comments on commit 02bb599

Please sign in to comment.