Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions internal/stackql/httpbuild/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,6 @@ func BuildHTTPRequestCtx(handlerCtx *handler.HandlerContext, node sqlparser.SQLN
return nil, err
}
log.Infoln(fmt.Sprintf("pre transform: httpArmoury.RequestParams[%d] = %s", i, string(p.BodyBytes)))
if handlerCtx.RuntimeContext.HTTPLogEnabled {
// url, _ := p.Context.GetUrl()
// handlerCtx.OutErrFile.Write([]byte(fmt.Sprintln(fmt.Sprintf("http request url: %s", url))))
}
log.Infoln(fmt.Sprintf("post transform: httpArmoury.RequestParams[%d] = %s", i, string(p.BodyBytes)))
secondPassParams[i] = p
}
Expand Down Expand Up @@ -314,10 +310,6 @@ func BuildHTTPRequestCtxFromAnnotation(handlerCtx *handler.HandlerContext, param

p.Request = baseRequestCtx
log.Infoln(fmt.Sprintf("pre transform: httpArmoury.RequestParams[%d] = %s", i, string(p.BodyBytes)))
if handlerCtx.RuntimeContext.HTTPLogEnabled {
// url, _ := p.Context.GetUrl()
// handlerCtx.OutErrFile.Write([]byte(fmt.Sprintln(fmt.Sprintf("http request url: %s", url))))
}
log.Infoln(fmt.Sprintf("post transform: httpArmoury.RequestParams[%d] = %s", i, string(p.BodyBytes)))
secondPassParams[i] = p
}
Expand Down
23 changes: 21 additions & 2 deletions internal/stackql/httpmiddleware/httpmiddleware.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package httpmiddleware

import (
"bytes"
"fmt"
"io"
"net/http"

"github.com/stackql/stackql/internal/stackql/handler"
Expand All @@ -26,12 +28,29 @@ func HttpApiCallFromRequest(handlerCtx handler.HandlerContext, prov provider.IPr
return nil, httpClientErr
}
request.Header.Del("Authorization")
if handlerCtx.RuntimeContext.HTTPLogEnabled {
urlStr := ""
if request != nil && request.URL != nil {
urlStr = request.URL.String()
}
handlerCtx.OutErrFile.Write([]byte(fmt.Sprintf("http request url: %s\n", urlStr)))
body := request.Body
if body != nil {
b, err := io.ReadAll(body)
if err != nil {
handlerCtx.OutErrFile.Write([]byte(fmt.Sprintf("error inpecting http request body: %s\n", err.Error())))
}
bodyStr := string(b)
request.Body = io.NopCloser(bytes.NewBuffer(b))
handlerCtx.OutErrFile.Write([]byte(fmt.Sprintf("http request body = '%s'\n", bodyStr)))
}
}
r, err := httpClient.Do(request)
if handlerCtx.RuntimeContext.HTTPLogEnabled {
if r != nil {
handlerCtx.OutErrFile.Write([]byte(fmt.Sprintln(fmt.Sprintf("http response status: %s", r.Status))))
handlerCtx.OutErrFile.Write([]byte(fmt.Sprintf("http response status: %s\n", r.Status)))
} else {
handlerCtx.OutErrFile.Write([]byte(fmt.Sprintln("http response came buck null")))
handlerCtx.OutErrFile.Write([]byte("http response came buck null\n"))
}
}
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion internal/stackql/provider/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ import (
log "github.com/sirupsen/logrus"
)

var (
gitHubLinksNextRegex *regexp.Regexp = regexp.MustCompile(`.*<(?P<nextURL>[^>]*)>;\ rel="next".*`)
)

type GenericProvider struct {
provider *openapistackql.Provider
runtimeCtx dto.RuntimeCtx
Expand Down Expand Up @@ -428,7 +432,6 @@ func (gp *GenericProvider) InferNextPageResponseElement(ho dto.Heirarchy) *dto.H
return nil, fmt.Errorf("cannot ingest purported http header of type = '%T'", h)
}
s := h.Values("Link")
gitHubLinksNextRegex := regexp.MustCompile(`.*<(?P<nextURL>[^>]*)>;\ rel="next".*`)
resArr := gitHubLinksNextRegex.FindStringSubmatch(strings.Join(s, ","))
if len(resArr) == 2 {
return resArr[1], nil
Expand Down