browser: do not send requests with too long URLs
This commit is contained in:
parent
cf48818c24
commit
4fbfa37937
|
@ -9,12 +9,19 @@ from bebop.page import Page
|
||||||
from bebop.protocol import Request, Response
|
from bebop.protocol import Request, Response
|
||||||
|
|
||||||
|
|
||||||
|
MAX_URL_LEN = 1024
|
||||||
|
|
||||||
|
|
||||||
def open_gemini_url(browser: Browser, url, redirects=0, history=True,
|
def open_gemini_url(browser: Browser, url, redirects=0, history=True,
|
||||||
use_cache=True):
|
use_cache=True):
|
||||||
"""Open a Gemini URL and set the formatted response as content.
|
"""Open a Gemini URL and set the formatted response as content.
|
||||||
|
|
||||||
After initiating the connection, TODO
|
After initiating the connection, TODO
|
||||||
"""
|
"""
|
||||||
|
if len(url) >= MAX_URL_LEN:
|
||||||
|
browser.set_status_error(f"Request URL too long.")
|
||||||
|
return
|
||||||
|
|
||||||
browser.set_status(f"Loading {url}")
|
browser.set_status(f"Loading {url}")
|
||||||
|
|
||||||
if use_cache and url in browser.cache:
|
if use_cache and url in browser.cache:
|
||||||
|
@ -58,7 +65,6 @@ def open_gemini_url(browser: Browser, url, redirects=0, history=True,
|
||||||
if not response:
|
if not response:
|
||||||
browser.set_status_error(f"Server response parsing failed ({url}).")
|
browser.set_status_error(f"Server response parsing failed ({url}).")
|
||||||
return
|
return
|
||||||
response.url = url
|
|
||||||
|
|
||||||
if response.code == 20:
|
if response.code == 20:
|
||||||
handle_response_content(browser, url, response, history)
|
handle_response_content(browser, url, response, history)
|
||||||
|
@ -149,6 +155,7 @@ def handle_input_request(browser: Browser, from_url: str, message: str =None):
|
||||||
else:
|
else:
|
||||||
browser.set_status("Input needed:")
|
browser.set_status("Input needed:")
|
||||||
user_input = browser.command_line.focus("?")
|
user_input = browser.command_line.focus("?")
|
||||||
if user_input:
|
if not user_input:
|
||||||
url = set_parameter(from_url, user_input)
|
return
|
||||||
open_gemini_url(browser, url)
|
url = set_parameter(from_url, user_input)
|
||||||
|
open_gemini_url(browser, url)
|
||||||
|
|
Reference in a new issue