diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 4d026a8a..17ab8c0d 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -6,6 +6,7 @@ - feat: add builtin function `environ`/`ENV` - fix: demo function compatibility +- fix #1240: losing host port in har2case - change: get hrp version from aliyun OSS file when installing ## v4.0.0-beta (2022-04-24) diff --git a/hrp/internal/har2case/core.go b/hrp/internal/har2case/core.go index 5852ee4c..d3772dd2 100644 --- a/hrp/internal/har2case/core.go +++ b/hrp/internal/har2case/core.go @@ -187,7 +187,7 @@ func (s *tStep) makeRequestURL(entry *Entry) error { log.Error().Err(err).Msg("make request url failed") return err } - s.Request.URL = fmt.Sprintf("%s://%s", u.Scheme, u.Hostname()+u.Path) + s.Request.URL = fmt.Sprintf("%s://%s", u.Scheme, u.Host+u.Path) return nil } diff --git a/hrp/internal/har2case/core_test.go b/hrp/internal/har2case/core_test.go index fae4a3f5..25779e12 100644 --- a/hrp/internal/har2case/core_test.go +++ b/hrp/internal/har2case/core_test.go @@ -142,6 +142,23 @@ func TestGetFilenameWithoutExtension(t *testing.T) { } } +func TestMakeRequestURL(t *testing.T) { + har := NewHAR("") + entry := &Entry{ + Request: Request{ + URL: "http://127.0.0.1:8080/api/login", + }, + } + step, err := har.prepareTestStep(entry) + if !assert.NoError(t, err) { + t.Fatal() + } + + if !assert.Equal(t, "http://127.0.0.1:8080/api/login", step.Request.URL) { + t.Fatal() + } +} + func TestMakeRequestHeaders(t *testing.T) { har := NewHAR("") entry := &Entry{