MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / DoStream

Method DoStream

internal/pluginhost/http_bridge.go:60–106  ·  view source on GitHub ↗
(ctx context.Context, req pluginapi.HTTPRequest)

Source from the content-addressed store, hash-verified

58}
59
60func (c *hostHTTPClient) DoStream(ctx context.Context, req pluginapi.HTTPRequest) (pluginapi.HTTPStreamResponse, error) {
61 if ctx == nil {
62 ctx = context.Background()
63 }
64 resp, cfg, errDo := c.doHTTP(ctx, req)
65 if errDo != nil {
66 return pluginapi.HTTPStreamResponse{}, errDo
67 }
68 helps.RecordAPIResponseMetadata(ctx, cfg, resp.StatusCode, resp.Header.Clone())
69 chunks := make(chan pluginapi.HTTPStreamChunk)
70 go func() {
71 defer close(chunks)
72 defer func() {
73 if errClose := resp.Body.Close(); errClose != nil {
74 log.Warnf("pluginhost: stream response body close error: %v", errClose)
75 }
76 }()
77 buf := make([]byte, 32*1024)
78 for {
79 n, errRead := resp.Body.Read(buf)
80 if n > 0 {
81 payload := bytes.Clone(buf[:n])
82 helps.AppendAPIResponseChunk(ctx, cfg, payload)
83 select {
84 case <-ctx.Done():
85 return
86 case chunks <- pluginapi.HTTPStreamChunk{Payload: payload}:
87 }
88 }
89 if errRead != nil {
90 if errRead != io.EOF {
91 helps.RecordAPIResponseError(ctx, cfg, errRead)
92 select {
93 case <-ctx.Done():
94 case chunks <- pluginapi.HTTPStreamChunk{Err: errRead}:
95 }
96 }
97 return
98 }
99 }
100 }()
101 return pluginapi.HTTPStreamResponse{
102 StatusCode: resp.StatusCode,
103 Headers: cloneHeader(resp.Header),
104 Chunks: chunks,
105 }, nil
106}
107
108func (c *hostHTTPClient) doHTTP(ctx context.Context, req pluginapi.HTTPRequest) (*http.Response, *config.Config, error) {
109 if c == nil || c.host == nil {

Callers

nothing calls this directly

Calls 8

doHTTPMethod · 0.95
AppendAPIResponseChunkFunction · 0.92
RecordAPIResponseErrorFunction · 0.92
cloneHeaderFunction · 0.70
CloseMethod · 0.65
CloneMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected