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

FastHTTP parsing is messing up my request #1942

Open
ruizlenato opened this issue Jan 21, 2025 · 7 comments
Open

FastHTTP parsing is messing up my request #1942

ruizlenato opened this issue Jan 21, 2025 · 7 comments

Comments

@ruizlenato
Copy link

ruizlenato commented Jan 21, 2025

I need to make a GET request using fashttp but my URL is being parsed and I can't get the correct response.
I've added DisablePathNormalizing: true to my client but it's still parsing.

Original URL: http://sns-webpic-qc.xhscdn.com/202501220243/0cefc8f02aa7fbfa04da7dcd33cb0c16/notes_pre_post/1040g3k831c60utqsgmag49snd3drpkggob6652o!nd_dft_wlteh_jpg_3
Parsed: http://sns-webpic-qc.xhscdn.com/202501220243/0cefc8f02aa7fbfa04da7dcd33cb0c16/notes_pre_post/1040g3k831c60utqsgmag49snd3drpkggob6652o%21nd_dft_wlteh_jpg_3

The parsed URL doesn't work, here's an example in my browser.
Original:
Image

Parsed:

Image

@erikdubbelboer
Copy link
Collaborator

Try setting Request.DisableRedirectPathNormalizing to true.

@ruizlenato
Copy link
Author

Try setting Request.DisableRedirectPathNormalizing to true.

I tried it earlier today and it's still the same thing.

@erikdubbelboer
Copy link
Collaborator

Can you share a reproducible example?

@ruizlenato
Copy link
Author

ruizlenato commented Jan 22, 2025

Can you share a reproducible example?

Without Request.DisableRedirectPathNormalizing:

➜ cat main.go
package main

import (
        "fmt"

        "github.com/valyala/fasthttp"
)

const url = "http://sns-webpic-qc.xhscdn.com/202501220243/0cefc8f02aa7fbfa04da7dcd33cb0c16/notes_pre_post/1040g3k831c60utqsgmag49snd3drpkggob6652o!nd_dft_wlteh_jpg_3"

func main() {
        client := &fasthttp.Client{}

        request := fasthttp.AcquireRequest()
        response := fasthttp.AcquireResponse()

        defer fasthttp.ReleaseRequest(request)
        defer fasthttp.ReleaseResponse(response)

        request.SetRequestURI(url)

        if err := client.Do(request, response); err != nil {
                fmt.Println("Error:", err)
        }

        fmt.Println("Status code:", response.StatusCode())
        fmt.Println("Request URL", request.URI().String())
}
➜ go run main.go
Status code: 403
Request URL http://sns-webpic-qc.xhscdn.com/202501220243/0cefc8f02aa7fbfa04da7dcd33cb0c16/notes_pre_post/1040g3k831c60utqsgmag49snd3drpkggob6652o%21nd_dft_wlteh_jpg_3

With Request.DisableRedirectPathNormalizing:

➜ cat main.go
package main

import (
        "fmt"

        "github.com/valyala/fasthttp"
)

const url = "http://sns-webpic-qc.xhscdn.com/202501220243/0cefc8f02aa7fbfa04da7dcd33cb0c16/notes_pre_post/1040g3k831c60utqsgmag49snd3drpkggob6652o!nd_dft_wlteh_jpg_3"

func main() {
        client := &fasthttp.Client{}

        request := fasthttp.AcquireRequest()
        response := fasthttp.AcquireResponse()

        defer fasthttp.ReleaseRequest(request)
        defer fasthttp.ReleaseResponse(response)

        request.SetRequestURI(url)
        request.DisableRedirectPathNormalizing = true

        if err := client.Do(request, response); err != nil {
                fmt.Println("Error:", err)
        }

        fmt.Println("Status code:", response.StatusCode())
        fmt.Println("Request URL", request.URI().String())
}
➜ go run main.go
Status code: 403
Request URL http://sns-webpic-qc.xhscdn.com/202501220243/0cefc8f02aa7fbfa04da7dcd33cb0c16/notes_pre_post/1040g3k831c60utqsgmag49snd3drpkggob6652o%21nd_dft_wlteh_jpg_3

@erikdubbelboer
Copy link
Collaborator

Sorry by bad, you have to set client.DisablePathNormalizing = true before you make the request. We have the DisablePathNormalizing at way to many levels and I agree it's super confusing.

@ruizlenato
Copy link
Author

ruizlenato commented Jan 23, 2025

Sorry by bad, you have to set client.DisablePathNormalizing = true before you make the request. We have the DisablePathNormalizing at way to many levels and I agree it's super confusing.

and when I use DoRedirects?

➜ bat main.go
───────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: main.go
───────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ package main
   2   │
   3   │ import (
   4   │     "fmt"
   5   │
   6   │     "github.com/valyala/fasthttp"
   7   │ )
   8   │
   9   │ const url = "http://sns-webpic-qc.xhscdn.com/202501220243/0cefc8f02aa7fbfa04da7dcd33cb0c16/notes_pre_post/1040g3k831c60utqsgmag49snd3drpkggob6652o!nd_dft_wlteh_jpg_3"
  10   │
  11   │ func main() {
  12   │     client := &fasthttp.Client{}
  13   │
  14   │     request := fasthttp.AcquireRequest()
  15   │     response := fasthttp.AcquireResponse()
  16   │
  17   │     defer fasthttp.ReleaseRequest(request)
  18   │     defer fasthttp.ReleaseResponse(response)
  19   │
  20   │     client.DisablePathNormalizing = true
  21   │     request.SetRequestURI(url)
  22   │
  23   │     if err := client.DoRedirects(request, response, 2); err != nil {
  24   │         fmt.Println("Error:", err)
  25   │     }
  26   │
  27   │     fmt.Println("Status code:", response.StatusCode())
  28   │     fmt.Println("Request URL", request.URI().String())
  29   │ }
───────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
➜ go run main.go
Status code: 403
Request URL http://sns-webpic-qc.xhscdn.com/202501220243/0cefc8f02aa7fbfa04da7dcd33cb0c16/notes_pre_post/1040g3k831c60utqsgmag49snd3drpkggob6652o%21nd_dft_wlteh_jpg_3

@erikdubbelboer
Copy link
Collaborator

I can't test cause I always seem to get a 403 on that url, also when I request it with curl or a browser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants