{"id":19866566,"url":"https://github.com/meaxsom/cc-51-forward-proxy-java","last_synced_at":"2026-04-24T23:33:17.308Z","repository":{"id":225730668,"uuid":"766584719","full_name":"meaxsom/cc-51-forward-proxy-java","owner":"meaxsom","description":"Coding Challenge #51 - Forward Proxy in Java","archived":false,"fork":false,"pushed_at":"2024-03-08T21:49:20.000Z","size":125,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-11T15:48:09.247Z","etag":null,"topics":["coding-challenge","forward-proxy","gradle","java","log4","vscode"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/meaxsom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-03T17:05:40.000Z","updated_at":"2024-03-23T10:10:19.000Z","dependencies_parsed_at":"2024-03-08T22:46:57.152Z","dependency_job_id":null,"html_url":"https://github.com/meaxsom/cc-51-forward-proxy-java","commit_stats":null,"previous_names":["meaxsom/cc-51-forward-proxy-java"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meaxsom%2Fcc-51-forward-proxy-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meaxsom%2Fcc-51-forward-proxy-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meaxsom%2Fcc-51-forward-proxy-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meaxsom%2Fcc-51-forward-proxy-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/meaxsom","download_url":"https://codeload.github.com/meaxsom/cc-51-forward-proxy-java/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241275693,"owners_count":19937390,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["coding-challenge","forward-proxy","gradle","java","log4","vscode"],"created_at":"2024-11-12T15:26:23.671Z","updated_at":"2026-04-24T23:33:17.282Z","avatar_url":"https://github.com/meaxsom.png","language":"Java","readme":"# Coding Challenge 51: Forward Proxy\n\n## Background\nChallenge #51 is for a [forward proxy](https://codingchallenges.substack.com/p/coding-challenge-51-http-forward). \n\nThis effort will use:\n- Java - an OpenJDK Java implmentation version 11 or better\n- Gradle - as the build process - using Groovy as the DSL\n- git for source control - pushed up to github\n\n## Step 1\n- Useful article on [creating an HTTP server in Java](https://rjlfinn.medium.com/creating-a-http-server-in-java-9b6af7f9b3cd)\n- Exposed to [`Optionals`](https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html) in Swift, but had not ecounterd them in Java before\n- [httpbin.org](http://httpbin.org/) is a nice HTTP/HTTPS Request \u0026 Response Service\n\n\n## Step 2 Banned Hosts\nPretty straight forward:\n- added a command line switch to `CommandLineHelper` for getting the name of the file containing banned hosts\n- added a `CommandLineHelper` method w/test to read the file into a `List`\n- ammended the `FwdProxy` class to accept the list of banned host names and hand it to the `ProxyHandler` class on construction\n- added a method w/test to evaluate a host against the banned list\n- had the `FwdProxy` class call the method to see if the host was banned\n- had to refactor the `handleInvalidResponse` method to supply a custom message and a `ResponseCode` to allow for better customization of error handling responses.\n- added `400 Forbidden` to `ResponseCode`\n- updated version number to \"0.2.0\"\n\n\n## Step 3: Banned Words\n- much the same wiring process for banned hosts:\n    - read in with `CommandLineHelper` - some refactoring to make it more generic\n    - hand it off to `FwdProxy` for use with `ProxyHandler`\n    - create a method to check for banned words and return result\n    - sent approperate response if check fails\n\n\n## Step 4: Log Activity\n- log activity to a file and console\n    - use `Log4J` to set up a console and access log config tied to a class\n        - modify based on preference\n    - create `AccessLogger` class to handle standard types of logging\n    - profit!\n\n## Step 5: HTTPS Tunnel\n- Request has `CONNECT` instead of `GET` as the HTTP `verb` that tells the server it needs an HTTPS tunnel.\n    - [Handling CONNECT messsage from client](https://greenbytes.de/tech/webdav/draft-ietf-httpbis-p2-semantics-26.html#CONNECT)\n    - [Responding to a CONNECT](https://stackoverflow.com/questions/28495938/how-do-i-respond-to-a-connect-method-request-in-a-proxy-server-using-socket-in)\n    \n- Ended up being simpler than I thought but I over complicated the solution initially and had to find my way back to a simplier path.\n- Hooking the host/port up to my browser it's successfully proxying browser requests!\n- I think we're done here!!\n\n## Notes\n- Wanted to use a Java dev container enviornment for development but found is slow\n\n- for server reading from ssl socket\n    - [SSL/TSL Socket Overlay](https://docs.oracle.com/javase/7/docs/api/javax/net/ssl/SSLSocketFactory.html#createSocket%28java.net.Socket,%20java.lang.String,%20int,%20boolean%29)\n    - [SSL Server Socket Example](https://stackoverflow.com/questions/47068155/is-it-possible-to-use-java-serversocket-to-accept-https-requests)\n    - [SSL/TSL Server Code Sample](http://www.java2s.com/Tutorial/Java/0490__Security/HttpsSocketClient.htm)\n\n- [for tunneling](https://github.com/mukatee/java-tcp-tunnel/blob/master/src/net/kanstren/tcptunnel/forwarder/TCPTunnel.java)\n- [simpler tunneling](https://stackoverflow.com/questions/18273703/tunneling-two-socket-client-in-java)\n\n- Example HTTP Request w/Headers\n\n```\nGET /kl;sjdfjskl/sdfasdf.xml?peter=bob\u0026jack=jill HTTP/1.1\nHost: localhost:8989\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:123.0) Gecko/20100101 Firefox/123.0\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8\nAccept-Language: en-US,en;q=0.5\nAccept-Encoding: gzip, deflate, br\nConnection: keep-alive\nUpgrade-Insecure-Requests: 1\nSec-Fetch-Dest: document\nSec-Fetch-Mode: navigate\nSec-Fetch-Site: none\nSec-Fetch-User: ?1\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeaxsom%2Fcc-51-forward-proxy-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmeaxsom%2Fcc-51-forward-proxy-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeaxsom%2Fcc-51-forward-proxy-java/lists"}