-
Notifications
You must be signed in to change notification settings - Fork 934
Add protocol as a separate property for FirebaseStorage service #5453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,7 +136,8 @@ export function connectStorageEmulator( | |
mockUserToken?: EmulatorMockTokenOptions | string; | ||
} = {} | ||
): void { | ||
storage.host = `http://${host}:${port}`; | ||
storage.host = `${host}:${port}`; | ||
storage.protocol = 'http'; | ||
const { mockUserToken } = options; | ||
if (mockUserToken) { | ||
storage._overrideAuthToken = | ||
|
@@ -149,7 +150,7 @@ export function connectStorageEmulator( | |
/** | ||
* A service that provides Firebase Storage Reference instances. | ||
* @param opt_url - gs:// url to a custom Storage Bucket | ||
* | ||
* | ||
* @internal | ||
*/ | ||
export class FirebaseStorageImpl implements FirebaseStorage { | ||
|
@@ -158,9 +159,9 @@ export class FirebaseStorageImpl implements FirebaseStorage { | |
* This string can be in the formats: | ||
* - host | ||
* - host:port | ||
* - protocol://host:port | ||
*/ | ||
private _host: string = DEFAULT_HOST; | ||
protocol: string = 'https'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this need to be exposed via the API? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This whole class is internal so it shouldn't be exposed publicly. But it can't be private since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The rest of the class does use underscores. I merely asked because of the change in the API report as it is not obvious that this is not exposed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added an underscore. |
||
protected readonly _appId: string | null = null; | ||
private readonly _requests: Set<Request<unknown>>; | ||
private _deleted: boolean = false; | ||
|
@@ -201,8 +202,7 @@ export class FirebaseStorageImpl implements FirebaseStorage { | |
|
||
/** | ||
* Set host string for this service. | ||
* @param host - host string in the form of host, host:port, | ||
* or protocol://host:port | ||
* @param host - host string in the form of host or host:port | ||
*/ | ||
set host(host: string) { | ||
this._host = host; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* @license | ||
* Copyright 2021 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import { expect } from 'chai'; | ||
import { DEFAULT_HOST } from '../../src/implementation/constants'; | ||
import { Location } from '../../src/implementation/location'; | ||
|
||
describe('Firebase Storage > Location', () => { | ||
it('makeFromUrl handles an emulator url correctly', () => { | ||
const loc = Location.makeFromUrl( | ||
'http://localhost:3001/v0/b/abcdefg.appspot.com/o/abcde.txt', | ||
'localhost:3001' | ||
); | ||
expect(loc.bucket).to.equal('abcdefg.appspot.com'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we test the protocol here as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Location doesn't seem to store the host or the protocol, makeFromUrl just uses them to do regex matches and then throws them away. It only seems to have bucket, and path (just the part after the bucket). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, got it. |
||
}); | ||
it('makeFromUrl handles a Firebase Storage url correctly', () => { | ||
const loc = Location.makeFromUrl( | ||
'https://firebasestorage.googleapis.com/v0/b/abcdefgh.appspot.com/o/abcde.txt', | ||
DEFAULT_HOST | ||
); | ||
expect(loc.bucket).to.equal('abcdefgh.appspot.com'); | ||
}); | ||
it('makeFromUrl handles a gs url correctly', () => { | ||
const loc = Location.makeFromUrl( | ||
'gs://mybucket/child/path/abcde.txt', | ||
DEFAULT_HOST | ||
); | ||
expect(loc.bucket).to.equal('mybucket'); | ||
}); | ||
it('makeFromUrl handles a Cloud Storage url correctly', () => { | ||
const loc = Location.makeFromUrl( | ||
'https://storage.googleapis.com/mybucket/abcde.txt', | ||
DEFAULT_HOST | ||
); | ||
expect(loc.bucket).to.equal('mybucket'); | ||
}); | ||
}); |
Uh oh!
There was an error while loading. Please reload this page.