surf
surf copied to clipboard
Surf get and post requests do not work
When I tried surf for make get request on https://static.crates.io/crates/{crate}/{crate}-{version}.crate
for example I get CloudFront responding 501 Not Yet Implemented, "The request could not be satisfied". Cloudfront is not the only website that do not like surf's get requests.
I also tried to make surf post requests, those only worked with the curl-client
as the hyper-client
do not send the body to the server. There is already an open issue about this #46.
So I end up doing crazy things that worked, I declared two dependencies of the same package and use the one with curl for the post and the one with hyper for the get requests.
[dependencies.surf]
git = "https://github.com/badboy/surf.git"
branch = "hyper-client"
default-features = false
features = ["hyper-client"]
[dependencies.surf-curl]
package = "surf"
git = "https://github.com/rustasync/surf.git"
branch = "master"
Get and Post raw requests
Get requests with the curl feature (does not work)
A typical get request with surf:
GET /crates/pcsc/pcsc-2.2.0.crate HTTP/1.1
Host: 127.0.0.1:8000
Accept: */*
Accept-Encoding: deflate, gzip
user-agent: curl/7.54.0 isahc/0.7.3
transfer-encoding: chunked
Expect: 100-continue
0
And here is one working with the curl command line:
GET /crates/pcsc/pcsc-2.2.0.crate HTTP/1.1 HTTP/1.1
Host: 127.0.0.1:8000
User-Agent: curl/7.54.0
Accept: */*
Post requests with the hyper feature (does not work)
Here is one post request with surf:
POST /indexes/bf16b15f/documents HTTP/1.1
x-meili-api-key: ckxGd3f97DXVKAhfkZ2mBTSc
content-type: application/json
host: 127.0.0.1:8000
transfer-encoding: chunked
0
And here is one using the curl command:
POST /indexes/bf16b15f/documents HTTP/1.1
Host: 127.0.0.1:8000
User-Agent: curl/7.54.0
Accept: */*
Content-Length: 7
Content-Type: application/x-www-form-urlencoded
"Hello"
The problem with the GET request is transfer-encoding: chunked
, as far as I recall this should not be sent during a GET request, as there is no body to be chunked. Maybe this was intended to be TE: chunked
to request the response as chunked encoding (but that's unnecessary as chunked
is an encoding that's required to be supported so doesn't need requesting).
This appears to be an isahc
integration issue, because of how it detects whether a request has a body it will always assume that an async-read based request without specified length has a body, even though there's definitely no body on this request.
@Nemo157 thanks for digging into this. as a fallback, I tested on isahc directly, and the request in question works fine there.