github.com/Jeffail/benthos/v3@v3.65.0/internal/http/docs/client.go (about) 1 package docs 2 3 import ( 4 "github.com/Jeffail/benthos/v3/internal/docs" 5 "github.com/Jeffail/benthos/v3/internal/metadata" 6 "github.com/Jeffail/benthos/v3/lib/util/http/auth" 7 "github.com/Jeffail/benthos/v3/lib/util/tls" 8 "github.com/Jeffail/gabs/v2" 9 ) 10 11 // ClientFieldSpec returns a field spec for an http client component. 12 func ClientFieldSpec(forOutput bool, extraChildren ...docs.FieldSpec) docs.FieldSpec { 13 httpSpecs := docs.FieldSpecs{ 14 docs.FieldCommon("url", "The URL to connect to.").HasType("string").IsInterpolated(), 15 docs.FieldCommon("verb", "A verb to connect with", "POST", "GET", "DELETE").HasType("string"), 16 docs.FieldString("headers", "A map of headers to add to the request.", map[string]interface{}{ 17 "Content-Type": "application/octet-stream", 18 }).IsInterpolated().Map().HasDefault(map[string]interface{}{ 19 "Content-Type": "application/octet-stream", 20 }), 21 docs.FieldAdvanced("metadata", "Specify optional matching rules to determine which metadata keys should be added to the HTTP request as headers."). 22 WithChildren(metadata.IncludeFilterDocs()...), 23 } 24 25 extractHeadersDesc := "Specify which response headers should be added to resulting messages as metadata. Header keys are lowercased before matching, so ensure that your patterns target lowercased versions of the header keys that you expect." 26 if forOutput { 27 extractHeadersDesc = "Specify which response headers should be added to resulting synchronous response messages as metadata. Header keys are lowercased before matching, so ensure that your patterns target lowercased versions of the header keys that you expect. This field is not applicable unless `propagate_response` is set to `true`." 28 } 29 30 httpSpecs = append(httpSpecs, auth.FieldSpecsExpanded()...) 31 httpSpecs = append(httpSpecs, tls.FieldSpec(), 32 docs.FieldDeprecated("copy_response_headers", "Sets whether to copy the headers from the response to the resulting payload."). 33 HasType(docs.FieldTypeBool).Advanced(), 34 docs.FieldAdvanced("extract_headers", extractHeadersDesc).WithChildren(metadata.IncludeFilterDocs()...), 35 docs.FieldString("rate_limit", "An optional [rate limit](/docs/components/rate_limits/about) to throttle requests by."), 36 docs.FieldString("timeout", "A static timeout to apply to requests."), 37 docs.FieldString("retry_period", "The base period to wait between failed requests.").Advanced(), 38 docs.FieldString("max_retry_backoff", "The maximum period to wait between failed requests.").Advanced(), 39 docs.FieldInt("retries", "The maximum number of retry attempts to make.").Advanced(), 40 docs.FieldInt("backoff_on", "A list of status codes whereby the request should be considered to have failed and retries should be attempted, but the period between them should be increased gradually.").Array().Advanced(), 41 docs.FieldInt("drop_on", "A list of status codes whereby the request should be considered to have failed but retries should not be attempted. This is useful for preventing wasted retries for requests that will never succeed. Note that with these status codes the _request_ is dropped, but _message_ that caused the request will not be dropped.").Array().Advanced(), 42 docs.FieldInt("successful_on", "A list of status codes whereby the attempt should be considered successful, this is useful for dropping requests that return non-2XX codes indicating that the message has been dealt with, such as a 303 See Other or a 409 Conflict. All 2XX codes are considered successful unless they are present within `backoff_on` or `drop_on`, regardless of this field.").Array().Advanced(), 43 docs.FieldString("proxy_url", "An optional HTTP proxy URL.").Advanced(), 44 ) 45 httpSpecs = append(httpSpecs, extraChildren...) 46 47 return docs.FieldComponent().WithChildren(httpSpecs...). 48 Linter((func(ctx docs.LintContext, line, col int, value interface{}) []docs.Lint { 49 if _, ok := value.(map[string]interface{}); !ok { 50 return nil 51 } 52 gObj := gabs.Wrap(value) 53 copyResponseHeaders, copyResponseHeadersSet := gObj.S("copy_response_headers").Data().(bool) 54 metaPrefixCount, _ := gObj.ArrayCountP("extract_headers.include_prefixes") 55 metaPatternCount, _ := gObj.ArrayCountP("extract_headers.include_patterns") 56 if copyResponseHeadersSet && copyResponseHeaders && (metaPrefixCount > 0 || metaPatternCount > 0) { 57 return []docs.Lint{ 58 docs.NewLintError(line, "Cannot use extract_headers when copy_response_headers is true."), 59 } 60 } 61 return nil 62 })) 63 }