2

I am processing a GET request in Go using fasthttp.

The query parameter test in this request is .%2A%2Ftoday%2F.%2A.

I am using POSTMAN to create the request, and the URL generated is:

http://localhost:3000/apiname/?test=.%252A%252Ftoday%252F.%252A

ctx.QueryArgs().Peek("test") gives me .*/today/.* instead of the original .%2A%2Ftoday%2F.%2A

I know I cannot partially encode/decode the request URL. Is there any way to get the original param as is?

Gavin
  • 4,365
  • 1
  • 18
  • 27
Alzio
  • 45
  • 9

1 Answers1

-1

Are you sure? I've just tested it and I'm getting the result you want.

This is the minimal working example:

package main

import (
    "fmt"
    "log"

    "github.com/fasthttp/router"
    "github.com/valyala/fasthttp"
)

func Test(ctx *fasthttp.RequestCtx) {
    ctx.Response.SetBodyString(string(ctx.QueryArgs().Peek("test")))
    fmt.Println(string(ctx.QueryArgs().Peek("test")))
}

func main() {

    r := router.New()
    r.GET("/test", Test)
    log.Fatal(fasthttp.ListenAndServe("127.0.0.1:8080", r.Handler))
}

This is the command line output after the GET request:

$ go run main.go                                                                                                                
.%2A%2Ftoday%2F.%2A

and this is the response in Postman:

enter image description here

Pablo L
  • 1,336
  • 1
  • 12
  • 25