diff --git a/examples/postman-echo.json b/examples/postman-echo.json index 9c26ec78..483852b0 100644 --- a/examples/postman-echo.json +++ b/examples/postman-echo.json @@ -33,7 +33,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "application/json; charset=utf-8", "msg": "assert response header Content-Type" @@ -75,7 +75,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "application/json; charset=utf-8", "msg": "assert response header Content-Type" @@ -129,7 +129,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "application/json; charset=utf-8", "msg": "assert response header Content-Type" @@ -177,7 +177,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "application/json; charset=utf-8", "msg": "assert response header Content-Type" @@ -231,7 +231,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "application/json; charset=utf-8", "msg": "assert response header Content-Type" @@ -285,7 +285,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "application/json; charset=utf-8", "msg": "assert response header Content-Type" @@ -337,7 +337,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "application/json; charset=utf-8", "msg": "assert response header Content-Type" @@ -374,7 +374,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "application/json; charset=utf-8", "msg": "assert response header Content-Type" @@ -420,7 +420,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "application/json; charset=utf-8", "msg": "assert response header Content-Type" @@ -460,7 +460,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "application/json; charset=utf-8", "msg": "assert response header Content-Type" @@ -500,7 +500,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "application/json; charset=utf-8", "msg": "assert response header Content-Type" @@ -540,7 +540,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "application/json; charset=utf-8", "msg": "assert response header Content-Type" @@ -589,7 +589,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "text/plain; charset=utf-8", "msg": "assert response header Content-Type" @@ -625,7 +625,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "application/json; charset=utf-8", "msg": "assert response header Content-Type" @@ -660,7 +660,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "application/json; charset=utf-8", "msg": "assert response header Content-Type" @@ -699,7 +699,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "text/plain; charset=utf-8", "msg": "assert response header Content-Type" @@ -733,7 +733,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "application/json; charset=utf-8", "msg": "assert response header Content-Type" @@ -766,7 +766,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "application/json; charset=utf-8", "msg": "assert response header Content-Type" @@ -832,7 +832,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "application/json; charset=utf-8", "msg": "assert response header Content-Type" @@ -871,7 +871,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "text/html; charset=utf-8", "msg": "assert response header Content-Type" @@ -904,7 +904,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "application/json; charset=utf-8", "msg": "assert response header Content-Type" @@ -949,7 +949,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "application/json; charset=utf-8", "msg": "assert response header Content-Type" @@ -994,7 +994,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "application/json; charset=utf-8", "msg": "assert response header Content-Type" @@ -1033,7 +1033,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "text/html; charset=utf-8", "msg": "assert response header Content-Type" @@ -1069,7 +1069,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "application/json; charset=utf-8", "msg": "assert response header Content-Type" @@ -1112,7 +1112,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "application/json; charset=utf-8", "msg": "assert response header Content-Type" @@ -1155,7 +1155,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "application/json; charset=utf-8", "msg": "assert response header Content-Type" @@ -1198,7 +1198,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "application/json; charset=utf-8", "msg": "assert response header Content-Type" @@ -1241,7 +1241,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "application/json; charset=utf-8", "msg": "assert response header Content-Type" @@ -1284,7 +1284,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "application/json; charset=utf-8", "msg": "assert response header Content-Type" @@ -1326,7 +1326,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "application/json; charset=utf-8", "msg": "assert response header Content-Type" @@ -1405,7 +1405,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "application/json; charset=utf-8", "msg": "assert response header Content-Type" @@ -1448,7 +1448,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "application/json; charset=utf-8", "msg": "assert response header Content-Type" @@ -1492,7 +1492,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "application/json; charset=utf-8", "msg": "assert response header Content-Type" @@ -1534,7 +1534,7 @@ "msg": "assert response status code" }, { - "check": "headers.Content-Type", + "check": "headers.\"Content-Type\"", "assert": "equals", "expect": "application/json; charset=utf-8", "msg": "assert response header Content-Type" diff --git a/examples/postman-echo.yaml b/examples/postman-echo.yaml index 78b5e9b5..ea92ed12 100644 --- a/examples/postman-echo.yaml +++ b/examples/postman-echo.yaml @@ -23,7 +23,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: application/json; charset=utf-8 msg: assert response header Content-Type @@ -53,7 +53,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: application/json; charset=utf-8 msg: assert response header Content-Type @@ -91,7 +91,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: application/json; charset=utf-8 msg: assert response header Content-Type @@ -125,7 +125,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: application/json; charset=utf-8 msg: assert response header Content-Type @@ -163,7 +163,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: application/json; charset=utf-8 msg: assert response header Content-Type @@ -201,7 +201,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: application/json; charset=utf-8 msg: assert response header Content-Type @@ -237,7 +237,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: application/json; charset=utf-8 msg: assert response header Content-Type @@ -263,7 +263,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: application/json; charset=utf-8 msg: assert response header Content-Type @@ -295,7 +295,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: application/json; charset=utf-8 msg: assert response header Content-Type @@ -323,7 +323,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: application/json; charset=utf-8 msg: assert response header Content-Type @@ -351,7 +351,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: application/json; charset=utf-8 msg: assert response header Content-Type @@ -379,7 +379,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: application/json; charset=utf-8 msg: assert response header Content-Type @@ -413,7 +413,7 @@ teststeps: assert: equals expect: 302 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: text/plain; charset=utf-8 msg: assert response header Content-Type @@ -439,7 +439,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: application/json; charset=utf-8 msg: assert response header Content-Type @@ -464,7 +464,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: application/json; charset=utf-8 msg: assert response header Content-Type @@ -492,7 +492,7 @@ teststeps: assert: equals expect: 302 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: text/plain; charset=utf-8 msg: assert response header Content-Type @@ -516,7 +516,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: application/json; charset=utf-8 msg: assert response header Content-Type @@ -539,7 +539,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: application/json; charset=utf-8 msg: assert response header Content-Type @@ -585,7 +585,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: application/json; charset=utf-8 msg: assert response header Content-Type @@ -612,7 +612,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: text/html; charset=utf-8 msg: assert response header Content-Type @@ -635,7 +635,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: application/json; charset=utf-8 msg: assert response header Content-Type @@ -666,7 +666,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: application/json; charset=utf-8 msg: assert response header Content-Type @@ -697,7 +697,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: application/json; charset=utf-8 msg: assert response header Content-Type @@ -724,7 +724,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: text/html; charset=utf-8 msg: assert response header Content-Type @@ -749,7 +749,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: application/json; charset=utf-8 msg: assert response header Content-Type @@ -779,7 +779,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: application/json; charset=utf-8 msg: assert response header Content-Type @@ -809,7 +809,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: application/json; charset=utf-8 msg: assert response header Content-Type @@ -839,7 +839,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: application/json; charset=utf-8 msg: assert response header Content-Type @@ -869,7 +869,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: application/json; charset=utf-8 msg: assert response header Content-Type @@ -899,7 +899,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: application/json; charset=utf-8 msg: assert response header Content-Type @@ -928,7 +928,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: application/json; charset=utf-8 msg: assert response header Content-Type @@ -982,7 +982,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: application/json; charset=utf-8 msg: assert response header Content-Type @@ -1012,7 +1012,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: application/json; charset=utf-8 msg: assert response header Content-Type @@ -1043,7 +1043,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: application/json; charset=utf-8 msg: assert response header Content-Type @@ -1072,7 +1072,7 @@ teststeps: assert: equals expect: 200 msg: assert response status code - - check: headers.Content-Type + - check: headers."Content-Type" assert: equals expect: application/json; charset=utf-8 msg: assert response header Content-Type diff --git a/internal/har2case/core_test.go b/internal/har2case/core_test.go index 0e17cfe2..96b0c232 100644 --- a/internal/har2case/core_test.go +++ b/internal/har2case/core_test.go @@ -101,7 +101,7 @@ func TestMakeTestCase(t *testing.T) { if !assert.Equal(t, "status_code", tCase.TestSteps[0].Validators[0].Check) { t.Fail() } - if !assert.Equal(t, "headers.Content-Type", tCase.TestSteps[0].Validators[1].Check) { + if !assert.Equal(t, "headers.\"Content-Type\"", tCase.TestSteps[0].Validators[1].Check) { t.Fail() } if !assert.Equal(t, "body.url", tCase.TestSteps[0].Validators[2].Check) { diff --git a/runner.go b/runner.go index 6e0ff4eb..ab685f15 100644 --- a/runner.go +++ b/runner.go @@ -628,7 +628,6 @@ func (r *caseRunner) runStepRequest(step *TStep) (stepResult *stepData, err erro ProtoMinor: 1, Close: true, // prevent the connection from being re-used } - var contentType string // prepare request headers if len(step.Request.Headers) > 0 { @@ -645,7 +644,6 @@ func (r *caseRunner) runStepRequest(step *TStep) (stepResult *stepData, err erro // prepare content length if strings.EqualFold(key, "Content-Length") && value != "" { - contentType = value if l, err := strconv.ParseInt(value, 10, 64); err == nil { req.ContentLength = l } @@ -697,6 +695,7 @@ func (r *caseRunner) runStepRequest(step *TStep) (stepResult *stepData, err erro var dataBytes []byte switch vv := data.(type) { case map[string]interface{}: + contentType := req.Header.Get("Content-Type") if strings.HasPrefix(contentType, "application/x-www-form-urlencoded") { // post form data formData := make(url.Values)