Skip to content

Commit

Permalink
Merge pull request #76 from vortex14/proxy-service-new-features
Browse files Browse the repository at this point in the history
updated
  • Loading branch information
vortex14 authored Feb 28, 2023
2 parents ca129ea + c5df63b commit ce341ac
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
15 changes: 8 additions & 7 deletions extensions/pipelines/http/net-http/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func (t *HttpRequestPipeline) UnpackRequestCtx(
okTr, transport := GetTransportCtx(ctx)

if (!okC || !okR) || (!okT || !okL || !okTr) {
logger.Errorf("client: %t , request: %t, transport: %t", okC, okR, okTr)
return false, nil, nil, nil, nil, nil
}

Expand All @@ -63,16 +64,16 @@ func (t *HttpRequestPipeline) Run(
return
}

ok, taskInstance, logger, client, request, transport := t.UnpackRequestCtx(context)

if !ok {
reject(t, Errors.PipelineContexFailed)
t.Cancel(context, logger, Errors.PipelineContexFailed)
return
}
_, logger := log.Get(context)

t.SafeRun(context, logger, func() error {

ok, taskInstance, logger, client, request, transport := t.UnpackRequestCtx(context)

if !ok {
return Errors.PipelineContexFailed
}

err, newContext := t.Fn(context, taskInstance, logger, client, request, transport)
if err != nil {
return err
Expand Down
18 changes: 17 additions & 1 deletion extensions/servers/gin/domains/proxy/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package proxy

import (
"fmt"
net_http "github.com/vortex14/gotyphoon/extensions/pipelines/http/net-http"
"net/http"
"net/url"
"os"
Expand All @@ -16,7 +17,7 @@ import (

"github.com/vortex14/gotyphoon/elements/models/timer"
"github.com/vortex14/gotyphoon/extensions/data/fake"
net_http "github.com/vortex14/gotyphoon/extensions/pipelines/http/net-http"
netHttp "github.com/vortex14/gotyphoon/extensions/pipelines/text/html"
net_html "github.com/vortex14/gotyphoon/extensions/pipelines/text/html"
"github.com/vortex14/gotyphoon/interfaces"
"github.com/vortex14/gotyphoon/log"
Expand Down Expand Up @@ -442,3 +443,18 @@ func TestGetConcurrentProxyCollection(t *testing.T) {
})
})
}

func TestMakeBlockProxy(t *testing.T) {
Convey("block the proxy", t, func() {
task := fake.CreateDefaultTask()

task.SetFetcherUrl("https://google.com")

err := netHttp.MakeRequestThroughProxy(task, func(logger interfaces.LoggerInterface,
response *http.Response, doc *goquery.Document) bool {

return !(response.StatusCode > 400)
})
So(err, ShouldBeNil)
})
}

0 comments on commit ce341ac

Please sign in to comment.