github.com/Jeffail/benthos/v3@v3.65.0/lib/output/http_client.go (about) 1 package output 2 3 import ( 4 "github.com/Jeffail/benthos/v3/internal/docs" 5 ihttpdocs "github.com/Jeffail/benthos/v3/internal/http/docs" 6 "github.com/Jeffail/benthos/v3/lib/log" 7 "github.com/Jeffail/benthos/v3/lib/message/batch" 8 "github.com/Jeffail/benthos/v3/lib/metrics" 9 "github.com/Jeffail/benthos/v3/lib/output/writer" 10 "github.com/Jeffail/benthos/v3/lib/types" 11 ) 12 13 func init() { 14 Constructors[TypeHTTPClient] = TypeSpec{ 15 constructor: fromSimpleConstructor(NewHTTPClient), 16 Summary: ` 17 Sends messages to an HTTP server.`, 18 Description: ` 19 When the number of retries expires the output will reject the message, the 20 behaviour after this will depend on the pipeline but usually this simply means 21 the send is attempted again until successful whilst applying back pressure. 22 23 The URL and header values of this type can be dynamically set using function 24 interpolations described [here](/docs/configuration/interpolation#bloblang-queries). 25 26 The body of the HTTP request is the raw contents of the message payload. If the 27 message has multiple parts (is a batch) the request will be sent according to 28 [RFC1341](https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html). This 29 behaviour can be disabled by setting the field ` + "[`batch_as_multipart`](#batch_as_multipart) to `false`" + `. 30 31 ### Propagating Responses 32 33 It's possible to propagate the response from each HTTP request back to the input 34 source by setting ` + "`propagate_response` to `true`" + `. Only inputs that 35 support [synchronous responses](/docs/guides/sync_responses) are able to make use of 36 these propagated responses.`, 37 Async: true, 38 Batches: true, 39 config: ihttpdocs.ClientFieldSpec(true, 40 docs.FieldAdvanced("batch_as_multipart", "Send message batches as a single request using [RFC1341](https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html). If disabled messages in batches will be sent as individual requests."), 41 docs.FieldAdvanced("propagate_response", "Whether responses from the server should be [propagated back](/docs/guides/sync_responses) to the input."), 42 docs.FieldCommon("max_in_flight", "The maximum number of messages to have in flight at a given time. Increase this to improve throughput."), 43 batch.FieldSpec(), 44 docs.FieldAdvanced( 45 "multipart", "EXPERIMENTAL: Create explicit multipart HTTP requests by specifying an array of parts to add to the request, each part specified consists of content headers and a data field that can be populated dynamically. If this field is populated it will override the default request creation behaviour.", 46 ).Array().HasType(docs.FieldTypeObject).HasDefault([]interface{}{}).WithChildren( 47 docs.FieldInterpolatedString("content_type", "The content type of the individual message part.", "application/bin").HasDefault(""), 48 docs.FieldInterpolatedString("content_disposition", "The content disposition of the individual message part.", `form-data; name="bin"; filename='${! meta("AttachmentName") }`).HasDefault(""), 49 docs.FieldInterpolatedString("body", "The body of the individual message part.", `${! json("data.part1") }`).HasDefault(""), 50 ).AtVersion("3.63.0"), 51 ), 52 Categories: []Category{ 53 CategoryNetwork, 54 }, 55 } 56 } 57 58 // NewHTTPClient creates a new HTTPClient output type. 59 func NewHTTPClient(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error) { 60 h, err := writer.NewHTTPClient(conf.HTTPClient, mgr, log, stats) 61 if err != nil { 62 return nil, err 63 } 64 w, err := NewAsyncWriter(TypeHTTPClient, conf.HTTPClient.MaxInFlight, h, log, stats) 65 if err != nil { 66 return w, err 67 } 68 if !conf.HTTPClient.BatchAsMultipart { 69 w = OnlySinglePayloads(w) 70 } 71 return NewBatcherFromConfig(conf.HTTPClient.Batching, w, mgr, log, stats) 72 }