Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for query_path with whitespace #4

Closed
wants to merge 1 commit into from
Closed
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
23 changes: 21 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ func NewClient(url, usr, pwd string, mods ...func(*Client)) (Client, error) {
return client, nil
}

// replaceWhitspace replaces space with URL Encoding %20 in URI
func replaceWhitespace(s string) string {
// Replace whitespace with %20
encodedURI := strings.ReplaceAll(s, " ", "%20")

return encodedURI
}

// Insecure determines if insecure https connections are allowed. Default value is true.
func Insecure(x bool) func(*Client) {
return func(client *Client) {
Expand Down Expand Up @@ -168,7 +176,11 @@ func DefaultMaxAsyncWaitTime(x int) func(*Client) {

// NewReq creates a new Req request for this client.
func (client Client) NewReq(method, uri string, body io.Reader, mods ...func(*Req)) Req {
httpReq, _ := http.NewRequest(method, client.Url+uri, body)

// Replace whitespace with %20
encodedURI := replaceWhitespace(uri)
httpReq, _ := http.NewRequest(method, client.Url+encodedURI, body)

req := Req{
HttpReq: httpReq,
LogPayload: true,
Expand Down Expand Up @@ -435,7 +447,14 @@ func pathWithOffset(path string, offset int) string {
sep = "&"
}

return fmt.Sprintf("%s%soffset=%d", path, sep, offset)
// Split the path into segments, encode each segment, and then join them back
segments := strings.Split(path, "/")
for i, segment := range segments {
segments[i] = replaceWhitespace(segment)
}
encodedPath := strings.Join(segments, "/")

return fmt.Sprintf("%s%soffset=%d", encodedPath, sep, offset)
}

type gatherer struct {
Expand Down
Loading