Skip to content
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

Fix host breaking when set to only port #116

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
yield message
// message will be done in the case of chat and generate
// message will be success in the case of a progress response (pull, push, create)
if ((message as any).done || (message as any).status === 'success') {

Check warning on line 48 in src/utils.ts

View workflow job for this annotation

GitHub Actions / test (16)

Unexpected any. Specify a different type

Check warning on line 48 in src/utils.ts

View workflow job for this annotation

GitHub Actions / test (16)

Unexpected any. Specify a different type

Check warning on line 48 in src/utils.ts

View workflow job for this annotation

GitHub Actions / test (18)

Unexpected any. Specify a different type

Check warning on line 48 in src/utils.ts

View workflow job for this annotation

GitHub Actions / test (18)

Unexpected any. Specify a different type

Check warning on line 48 in src/utils.ts

View workflow job for this annotation

GitHub Actions / test (20)

Unexpected any. Specify a different type

Check warning on line 48 in src/utils.ts

View workflow job for this annotation

GitHub Actions / test (20)

Unexpected any. Specify a different type
this.doneCallback()
return
}
Expand Down Expand Up @@ -171,7 +171,7 @@
data?: Record<string, unknown> | BodyInit,
options?: { signal: AbortSignal },
): Promise<Response> => {
const isRecord = (input: any): input is Record<string, unknown> => {

Check warning on line 174 in src/utils.ts

View workflow job for this annotation

GitHub Actions / test (16)

Unexpected any. Specify a different type

Check warning on line 174 in src/utils.ts

View workflow job for this annotation

GitHub Actions / test (18)

Unexpected any. Specify a different type

Check warning on line 174 in src/utils.ts

View workflow job for this annotation

GitHub Actions / test (20)

Unexpected any. Specify a different type
return input !== null && typeof input === 'object' && !Array.isArray(input)
}

Expand Down Expand Up @@ -266,7 +266,7 @@
if (host.startsWith(':')) {
// if host starts with ':', prepend the default hostname
host = `http://127.0.0.1${host}`
isExplicitProtocol = false
isExplicitProtocol = true
}

if (!isExplicitProtocol) {
Expand Down
8 changes: 8 additions & 0 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ describe('formatHost Function Tests', () => {
expect(formatHost('1.2.3.4:56789')).toBe('http://1.2.3.4:56789')
})

it('should parse with only a port', () => {
expect(formatHost(':56789')).toBe('http://127.0.0.1:56789')
})

it('should parse HTTP URL', () => {
expect(formatHost('http://1.2.3.4')).toBe('http://1.2.3.4:80')
})
Expand Down Expand Up @@ -52,4 +56,8 @@ describe('formatHost Function Tests', () => {
it('should handle trailing slash in domain with port', () => {
expect(formatHost('example.com:56789/')).toBe('http://example.com:56789')
})

it('should handle traling slash with only a port', () => {
expect(formatHost(':56789/')).toBe('http://127.0.0.1:56789')
})
})
Loading