Repository navigation
Closed
Labels
A-embeddingA-networkC-assignedThere is someone working on resolving the issueE-more-complexVariable effort required; may require a mentor. Recommended solution is clearly described in the iss
Description
servo/components/net/http_loader.rs
Lines 1571 to 1578 in 0836632
| if !http_request.use_url_credentials || authentication_fetch_flag { | |
| // FIXME: Prompt the user for username and password from the window | |
| // Wrong, but will have to do until we are able to prompt the user | |
| // otherwise this creates an infinite loop | |
| // We basically pretend that the user declined to enter credentials | |
| return response; | |
| } |
servo/components/net/http_loader.rs
Lines 1606 to 1612 in 0836632
| // Step 3 | |
| // FIXME: Prompt the user for proxy authentication credentials | |
| // Wrong, but will have to do until we are able to prompt the user | |
| // otherwise this creates an infinite loop | |
| // We basically pretend that the user declined to enter credentials | |
| return response; |
We will need to store an EmbedderProxy in HttpState. This will allow us to send messages to the embedder from within the HTTP fetching code linked earlier.
We can then send two EmbedderMsg::Prompt messages and wait on the responses from the channel that is sent as part of that message, which will contain the username and password values chosen by the user.
To test this, run the following code under python3:
Details
import http.server
import cgi
import base64
import json
from urllib.parse import urlparse, parse_qs
class CustomServerHandler(http.server.BaseHTTPRequestHandler):
def do_HEAD(self):
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.end_headers()
def do_AUTHHEAD(self):
self.send_response(401)
self.send_header(
'WWW-Authenticate', 'Basic realm="Demo Realm"')
self.send_header('Content-type', 'application/json')
self.end_headers()
def do_GET(self):
key = self.server.get_auth_key()
''' Present frontpage with user authentication. '''
if self.headers.get('Authorization') == None:
self.do_AUTHHEAD()
response = {
'success': False,
'error': 'No auth header received'
}
self.wfile.write(bytes(json.dumps(response), 'utf-8'))
elif self.headers.get('Authorization') == 'Basic ' + str(key):
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.end_headers()
getvars = self._parse_GET()
response = {
'path': self.path,
'get_vars': str(getvars)
}
base_path = urlparse(self.path).path
if base_path == '/path1':
# Do some work
pass
elif base_path == '/path2':
# Do some work
pass
self.wfile.write(bytes(json.dumps(response), 'utf-8'))
else:
self.do_AUTHHEAD()
response = {
'success': False,
'error': 'Invalid credentials'
}
self.wfile.write(bytes(json.dumps(response), 'utf-8'))
def do_POST(self):
key = self.server.get_auth_key()
''' Present frontpage with user authentication. '''
if self.headers.get('Authorization') == None:
self.do_AUTHHEAD()
response = {
'success': False,
'error': 'No auth header received'
}
self.wfile.write(bytes(json.dumps(response), 'utf-8'))
elif self.headers.get('Authorization') == 'Basic ' + str(key):
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.end_headers()
postvars = self._parse_POST()
getvars = self._parse_GET()
response = {
'path': self.path,
'get_vars': str(getvars),
'get_vars': str(postvars)
}
base_path = urlparse(self.path).path
if base_path == '/path1':
# Do some work
pass
elif base_path == '/path2':
# Do some work
pass
self.wfile.write(bytes(json.dumps(response), 'utf-8'))
else:
self.do_AUTHHEAD()
response = {
'success': False,
'error': 'Invalid credentials'
}
self.wfile.write(bytes(json.dumps(response), 'utf-8'))
response = {
'path': self.path,
'get_vars': str(getvars),
'get_vars': str(postvars)
}
self.wfile.write(bytes(json.dumps(response), 'utf-8'))
def _parse_POST(self):
ctype, pdict = cgi.parse_header(self.headers.getheader('content-type'))
if ctype == 'multipart/form-data':
postvars = cgi.parse_multipart(self.rfile, pdict)
elif ctype == 'application/x-www-form-urlencoded':
length = int(self.headers.getheader('content-length'))
postvars = cgi.parse_qs(
self.rfile.read(length), keep_blank_values=1)
else:
postvars = {}
return postvars
def _parse_GET(self):
getvars = parse_qs(urlparse(self.path).query)
return getvars
class CustomHTTPServer(http.server.HTTPServer):
key = ''
def __init__(self, address, handlerClass=CustomServerHandler):
super().__init__(address, handlerClass)
def set_auth(self, username, password):
self.key = base64.b64encode(
bytes('%s:%s' % (username, password), 'utf-8')).decode('ascii')
def get_auth_key(self):
return self.key
if __name__ == '__main__':
server = CustomHTTPServer(('', 8888))
server.set_auth('demo', 'demo')
server.serve_forever()
Metadata
Metadata
Assignees
Labels
A-embeddingA-networkC-assignedThere is someone working on resolving the issueE-more-complexVariable effort required; may require a mentor. Recommended solution is clearly described in the iss
Activity
mustafapc19 commentedon Jul 30, 2020
Can I try this? I might be able to do this. With your help ofcourse 🙂
jdm commentedon Jul 30, 2020
Go for it! Please ask questions if anything is unclear!
mustafapc19 commentedon Jul 31, 2020
Yeah. Assign me 👍
paulrouget commentedon Jul 31, 2020
I think it wouldn't be too hard to also introduce a
Prompt::Credentialhere:servo/components/embedder_traits/lib.rs
Line 116 in 9b6b793
jdm commentedon Jul 31, 2020
Agreed, but it will be easiest for a new contributor to use the existing messages rather than also introducing new ones.
mustafapc19 commentedon Jul 31, 2020
I'll try to implement prompt:: Credentials and if I fail to. I'll do the sending twice thingy
ritwickdsouza commentedon Sep 4, 2020
Hey @mustafapc19, are you still working on this task? If not can I work on it?
mustafapc19 commentedon Sep 4, 2020
I kinda have the pr almost ready but then Mozilla defunded the project. Should send the pr @jdm ?
ritwickdsouza commentedon Sep 4, 2020
Ah, i see. thanks
jdm commentedon Sep 4, 2020
I would review it :)
mustafapc19 commentedon Sep 7, 2020
Yeah. The issue I was facing then was that I was inserting the (http:: Authentication and the required string) in the response object's header map. But in server the Authentication header for some reason is None. Sadly I still can't figure. If u feel nostalgic about servo, u can help ? 🥺
jdm commentedon Sep 7, 2020
The header needs to be added to the request, rather than the response.
Wowo10 commentedon Apr 1, 2021
Since this looks to me like abandoned since half a year. Mind if I take over?
mustafapc19 commentedon Apr 1, 2021
Yeah sure. I think I have implemented the feature but I didn't get the time to write the test for it. Go for it 🚀
arthmis commentedon Dec 12, 2024
@jdm can I take on this issue?
jdm commentedon Dec 12, 2024
@arthmis Yes, that would be great!
arthmis commentedon Dec 14, 2024
so I've run into an issue. It seems prompting on windows doesn't work. I get a prompt window, I enter
demofor the username but then servo hangs/freezes. I tested the same code on my macbook and I can get through theusernameand then thepasswordprompt and receive those values in theIpcReceiver. So I'll have to look into why it's hanging on the prompt on windowsmukilan commentedon Dec 14, 2024
Just an FYI, I believe our Outreachy intern (@chickenleaf) also faced a similar issue recently. We are looking into replacing tinyfiledialog with egui-file-dialog and/or egui-modal. It is likely that the code that shows the dialog window and blocks the embedder thread will be removed soon. So I guess it should be fine to proceed with the changes for this issue, even if the problem with Windows can't be resolved and as long as it works on Linux and Mac.
cc: @mrobinson
chickenleaf commentedon Dec 14, 2024
@mukilan is this issue mentioned in the internship tasks? For the mini browser. I feel like I added this in my proposal?
mukilan commentedon Dec 14, 2024
Yes, I believe we so, but it should be fine as @arthmis has already started on the changes and we were likely not going to get around to it until later in the internship. Depending on how much of the implementation is complete at that point, we could probably work on enhancements or come up with other tasks for you.
arthmis commentedon Dec 14, 2024
I was going to continue development on my mac for this issue then look into the windows issue afterwards so that's good to hear.