From 6bc31ab0bedf0d22b5b9aef068c4646df1e1910d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 6 Nov 2024 14:35:03 -0500 Subject: [PATCH] Use Credentials.IsEmpty --- common/frame_session.go | 2 +- common/network_manager.go | 4 ++-- tests/browser_context_options_test.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/common/frame_session.go b/common/frame_session.go index 67ca6e58f..50c144d03 100644 --- a/common/frame_session.go +++ b/common/frame_session.go @@ -1149,7 +1149,7 @@ func (fs *FrameSession) updateHTTPCredentials(initial bool) error { fs.logger.Debugf("NewFrameSession:updateHttpCredentials", "sid:%v tid:%v", fs.session.ID(), fs.targetID) credentials := fs.page.browserCtx.opts.HTTPCredentials - if !initial || credentials != (Credentials{}) { + if !initial || !credentials.IsEmpty() { return fs.networkManager.Authenticate(credentials) } diff --git a/common/network_manager.go b/common/network_manager.go index 7f63eb7aa..be4840029 100644 --- a/common/network_manager.go +++ b/common/network_manager.go @@ -614,7 +614,7 @@ func (m *NetworkManager) onAuthRequired(event *fetch.EventAuthRequired) { case m.attemptedAuth[rid]: delete(m.attemptedAuth, rid) res = fetch.AuthChallengeResponseResponseCancelAuth - case m.credentials != Credentials{}: + case !m.credentials.IsEmpty(): // TODO: remove requests from attemptedAuth when: // - request is redirected // - loading finished @@ -721,7 +721,7 @@ func (m *NetworkManager) updateProtocolRequestInterception() error { // Authenticate sets HTTP authentication credentials to use. func (m *NetworkManager) Authenticate(credentials Credentials) error { m.credentials = credentials - if credentials != (Credentials{}) { + if !credentials.IsEmpty() { m.userReqInterceptionEnabled = true } if err := m.updateProtocolRequestInterception(); err != nil { diff --git a/tests/browser_context_options_test.go b/tests/browser_context_options_test.go index a17a7da23..b404a7fc4 100644 --- a/tests/browser_context_options_test.go +++ b/tests/browser_context_options_test.go @@ -24,7 +24,7 @@ func TestBrowserContextOptionsDefaultValues(t *testing.T) { assert.Empty(t, opts.ExtraHTTPHeaders) assert.Nil(t, opts.Geolocation) assert.False(t, opts.HasTouch) - assert.Nil(t, opts.HTTPCredentials) + assert.True(t, opts.HTTPCredentials.IsEmpty()) assert.False(t, opts.IgnoreHTTPSErrors) assert.False(t, opts.IsMobile) assert.True(t, opts.JavaScriptEnabled)