mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-27 05:15:47 +00:00
remote http request/response encoding
This commit is contained in:
@@ -1,42 +0,0 @@
|
|||||||
package processor
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
|
||||||
)
|
|
||||||
|
|
||||||
type HTTPRequestEncode struct {
|
|
||||||
config config.ProcessorConfig
|
|
||||||
}
|
|
||||||
|
|
||||||
func (hre *HTTPRequestEncode) Process(ctx context.Context, payload any) (any, error) {
|
|
||||||
payloadRequest, ok := payload.(*http.Request)
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
return nil, errors.New("http.request.encode processor only accepts an http.Request")
|
|
||||||
}
|
|
||||||
|
|
||||||
bytes, err := io.ReadAll(payloadRequest.Body)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return bytes, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (hre *HTTPRequestEncode) Type() string {
|
|
||||||
return hre.config.Type
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
RegisterProcessor(ProcessorRegistration{
|
|
||||||
Type: "http.request.encode",
|
|
||||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
|
||||||
return &HTTPRequestEncode{config: config}, nil
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
package processor
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
|
||||||
)
|
|
||||||
|
|
||||||
type HTTPResponseEncode struct {
|
|
||||||
config config.ProcessorConfig
|
|
||||||
}
|
|
||||||
|
|
||||||
func (hre *HTTPResponseEncode) Process(ctx context.Context, payload any) (any, error) {
|
|
||||||
payloadResponse, ok := payload.(*http.Response)
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
return nil, errors.New("http.response.encode processor only accepts an http.Response")
|
|
||||||
}
|
|
||||||
defer payloadResponse.Body.Close()
|
|
||||||
|
|
||||||
bytes, err := io.ReadAll(payloadResponse.Body)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return bytes, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (hre *HTTPResponseEncode) Type() string {
|
|
||||||
return hre.config.Type
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
RegisterProcessor(ProcessorRegistration{
|
|
||||||
Type: "http.response.encode",
|
|
||||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
|
||||||
return &HTTPResponseEncode{config: config}, nil
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package processor_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestHTTPRequestEncodeFromRegistry(t *testing.T) {
|
|
||||||
registration, ok := processor.ProcessorRegistry["http.request.encode"]
|
|
||||||
if !ok {
|
|
||||||
t.Fatalf("http.request.encode processor not registered")
|
|
||||||
}
|
|
||||||
|
|
||||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
|
||||||
Type: "http.request.encode",
|
|
||||||
})
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to create http.request.encode processor: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if processorInstance.Type() != "http.request.encode" {
|
|
||||||
t.Fatalf("http.request.encode processor has wrong type: %s", processorInstance.Type())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package processor_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestHTTPResponseEncodeFromRegistry(t *testing.T) {
|
|
||||||
registration, ok := processor.ProcessorRegistry["http.response.encode"]
|
|
||||||
if !ok {
|
|
||||||
t.Fatalf("http.response.encode processor not registered")
|
|
||||||
}
|
|
||||||
|
|
||||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
|
||||||
Type: "http.response.encode",
|
|
||||||
})
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to create http.response.encode processor: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if processorInstance.Type() != "http.response.encode" {
|
|
||||||
t.Fatalf("http.response.encode processor has wrong type: %s", processorInstance.Type())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -182,18 +182,6 @@
|
|||||||
"required": ["type", "params"],
|
"required": ["type", "params"],
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"type": "object",
|
|
||||||
"title": "Encode HTTP Request",
|
|
||||||
"properties": {
|
|
||||||
"type": {
|
|
||||||
"type": "string",
|
|
||||||
"const": "http.request.encode"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": ["type"],
|
|
||||||
"additionalProperties": false
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"title": "Filter HTTP Request",
|
"title": "Filter HTTP Request",
|
||||||
@@ -245,18 +233,6 @@
|
|||||||
"required": ["type", "params"],
|
"required": ["type", "params"],
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"type": "object",
|
|
||||||
"title": "Encode HTTP Response",
|
|
||||||
"properties": {
|
|
||||||
"type": {
|
|
||||||
"type": "string",
|
|
||||||
"const": "http.response.encode"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": ["type"],
|
|
||||||
"additionalProperties": false
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"title": "Parse Int",
|
"title": "Parse Int",
|
||||||
|
|||||||
Reference in New Issue
Block a user