pProxy, the first and only webproxy for Picotron!
This is the first release, so its still very much a work in progress, so far you can...
- Perform with requests with URLs over 256 Characters (fetch() is limited to 256 chars)
- Do GET, POST, HEAD, PUT, PATCH, DELETE, CONNECT, OPTIONS and TRACE requests
- Get more than just the body from your requests including status codes and headers
- Store cookies in a reusable client
For ideas, bugs, or help, contact me on the Picotron discord
https://discord.gg/XQStcpPeH4
Public Proxy List:
http pproxy.pyrochiliarch.com 8080
To install (For Users):
If you are trying to run a project that relies on pProxy, follow these instructions.
Details for devs are further down.
1) Load the installer with load #pproxy
and run it ctrl+r
to install
2) Configure which proxy server to use with pProxy config http pproxy.pyrochiliarch.com 8080
3) Use pProxy test
to check you connection, it should print the server version
Getting Started (For Devs):
The #pproxy cartridge is an installer, load it load #pproxy
and run it ctrl+r
to install
Once installed, configure the pProxy library to point to your proxy server using the pProxy
command
Use the following settings to use a public server pProxy config http pproxy.pyrochiliarch.com 8080
You may want to setup your own server, which can help with development.
https://github.com/PyroChiliarch/pProxy
Instructions to setup are in the github readme
pProxy test
will check your configuration settings
pProxy help
will print additional commands
Write a script
There are 4 main steps
1) Make a proxy newProxy()
2) Make a client newHttpClient()
3) Craft a request newRequest("get", "http://www.google.com", "")
4) Make the request doRequest(client, request)
A simple script would look like this
Note: the proxy and client should be reused
include("/appdata/system/lib/dynInclude.lua") dynInclude("pProxy") dynInclude("tabUtil") local function handleErr(err) if not (err==nil) then print("Error: ".. err) pause("space") exit(1) end end -- 1 Make new proxy proxy = pProxy:newProxy() -- 2 Make new client client, err = proxy:newHttpClient() handleErr(err) -- 3 Craft a request request = proxy:newRequest("post", "http://httpbin.org/anything", "This is the body contents") -- 4 Make the request data, err = proxy:doRequest(client, request) handleErr(err) print("Printing the response to the console:\n" .. tabUtil.toString(data)) |
<br><br>
The example below performs multiple different example request that should help
you understand how pProxy is used.
Near the end of this post is documentation on functions
include("/appdata/system/lib/dynInclude.lua") dynInclude("pProxy") dynInclude("tabUtil") local function handleErr(err) if not (err==nil) then print("Error: ".. err) pause("space") exit(1) end end --==========================-- -- Reused Values -- --==========================-- -- proxy is used in all requests -- the client is only used in Advanced requests -- Make new proxy proxy = pProxy:newProxy() -- Make new client client, err = proxy:newHttpClient() handleErr(err) --==========================-- -- Test connection -- --==========================-- print("=================================") print("Testing connection to proxy") ver, err = proxy:getVersion() handleErr(err) print("Connected to proxy version " .. ver) --==========================-- -- Simple Get -- --==========================-- print("\n\n=================================") print("Basic get request, like fetch but through proxy") body, err = proxy:simpleGet("http://httpbin.org/robots.txt") handleErr(err) print("Get request result:\n" .. body) --==========================-- -- Get with basic auth -- --==========================-- print("\n\n=================================") print("Perform basic auth") -- Perform a get request with headers for basic auth -- Build new request request = proxy:newRequest("get", "http://httpbin.org/basic-auth/%41%6C%61%64%64%69%6E/%6F%70%65%6E%20%73%65%73%61%6D%65", "") -- Add basic auth header username = "Aladdin" password = "open sesame" auth = ("Basic " .. basexx.to_base64(username .. ":" .. password)) request.addHeader("Authorization", auth) -- Do the request through the proxy data, err = proxy:doRequest(client, request) handleErr(err) -- Get the result print("Username: " .. username) print("Password: " .. password) print("Basic auth result:\n" .. data.status) --==========================-- -- Post request -- --==========================-- print("\n\n=================================") print("Do a post request and print the returned response") request = proxy:newRequest("post", "http://httpbin.org/anything", "This is the body contents") data, err = proxy:doRequest(client, request) handleErr(err) print("Post request, full results:\n" .. tabUtil.toString(data)) --==========================-- -- Get Cookies -- --==========================-- print("\n\n=================================") print("Make a request to get some cookies in our clients cookie jar,\nthen get the cookies from the client") request = proxy:newRequest("get", "http://httpbin.org/cookies/set?myFirstCookie=chocolateChip&visitedPage=True", "") data, err = proxy:doRequest(client, request) handleErr(err) print("response headers when getting some cookies:\n" .. tabUtil.toString(data.headers)) print("\nGetting cookies from the our client") data, err = proxy:getCookies(client, "http://httpbin.org/") handleErr(err) print("Here are the cookies:\n" .. tabUtil.toString(data)) |
Extra details:
Whats installed:
The pProxy.lua
library is installed to /appdata/system/lib/pProxy.lua
The dynInclude.lua
library is installed to /appdata/system/lib/dynInclude.lua
The pProxy.lua
command line configuration utility is installed to /appdata/system/lib/dynInclude.lua
Functions:
Format: (return) function (parameters)
(proxy table, error string) pProxy:newProxy() Create a new proxy table, reuse this table with all other commands (client string, error string) pProxy:newHttpClient() Returns a UUID representing the client object on the proxy (version string, error string) pProxy:getVersion() Get the version of the current proxy (response string) pProxy:simpleGet(url string) Perform a simple get request through the proxy, very similar to fetch() (request table) pProxy:newRequest(method string, url string, body string) Crafts a new request, method supports the following values: "GET", "POST", "HEAD", "PUT", "PATCH", "DELETE", "CONNECT", "OPTIONS" and "TRACE' () request.addHeader(name string, value string) Add a new header to your request https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers (response table, error string) pProxy:doRequest (client string, request table) Provide a client id string and a crafted request to the proxy, returns the response in a table (cookies table) pProxy:getCookies(client string, url string) Returns a table containing the cookies from the specified client, filtered by the host in the url "https://www.google.com" will filter all cookies matching "www.google.com" |
With all these recent software projects, Picotron is apparently becoming something I never expected it to be.
[Please log in to post a comment]