fuel
fuel copied to clipboard
415 Unsupported media type only through Fuel
Hi, I have a server I am trying to reach to. If I open a browser and simply enter the url of my endpoint, I can see the response. If I use curl curl localhost:9090/api/some-get-endpoint
I can see the response. Even when I try it in Postman, and create a simple GET request, it works. But if I try to reach the server using Fuel I get 415 Unsupported Media Type
.
This is the code I am running:
FuelManager.instance.basePath = "http://$host:$port/api"
"/position"
.httpGet()
.responseString(handler).join()
And the full error:
HTTP Exception 415 Unsupported Media Type
com.github.kittinunf.fuel.core.FuelError$Companion.wrap(FuelError.kt:84)
com.github.kittinunf.fuel.core.FuelError$Companion.wrap$default(FuelError.kt:83)
com.github.kittinunf.fuel.core.requests.RequestTaskCallbacks.call(RequestTaskCallbacks.kt:30)
com.github.kittinunf.fuel.core.requests.RequestTaskCallbacks.call(RequestTaskCallbacks.kt:20)
java.util.concurrent.FutureTask.run(FutureTask.java:266)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
java.lang.Thread.run(Thread.java:748)
Caused by: HTTP Exception 415 Unsupported Media Type
com.github.kittinunf.fuel.core.FuelError$Companion.wrap(FuelError.kt:86)
Caused by: com.github.kittinunf.fuel.core.HttpException: HTTP Exception 415 Unsupported Media Type
com.github.kittinunf.fuel.core.requests.RequestTask.prepareResponse(RequestTask.kt:35)
com.github.kittinunf.fuel.core.requests.RequestTask.call(RequestTask.kt:47)
com.github.kittinunf.fuel.core.requests.RequestTask.call(RequestTask.kt:14)
com.github.kittinunf.fuel.core.requests.RequestTaskCallbacks.call(RequestTaskCallbacks.kt:28)
com.github.kittinunf.fuel.core.requests.RequestTaskCallbacks.call(RequestTaskCallbacks.kt:20)
java.util.concurrent.FutureTask.run(FutureTask.java:266)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
java.lang.Thread.run(Thread.java:748)
I am sure I am missing something stupid, but I don't see what...
The API server thinks there is a content-type given, which is... weird because there is no body. Do you have access to the API server?
@SleeplessByte I created the served, but I am not really fluent in that area. It is written in C++, I used Pistache to make it. Here is a snippet of my code:
class Endpoints {
public:
explicit Endpoints(Address addr)
: httpEndpoint(std::make_shared<Http::Endpoint>(addr)) {}
explicit Endpoints() {}
void init() {
auto opts = Http::Endpoint::options().threads(3);
httpEndpoint->init(opts);
setupRoutes();
}
void start() {
httpEndpoint->setHandler(router.handler());
httpEndpoint->serve();
}
private:
void setupRoutes() {
using namespace Rest;
...
...
Routes::Get(router, "/api/position", Routes::bind(&Endpoints::cmdPosition, this));
}
void cmdPosition(const Rest::Request& request, Http::ResponseWriter response) {
// some code
}
std::shared_ptr<Http::Endpoint> httpEndpoint;
Rest::Router router;
};
I mean... The weird part is that every other client I used can connect to it, except Fuel. Which to me sounds like Fuel is sending something different than all the other clients do. Maybe you can copy the server code and try if it works for you?
I agree that this is weird. I don't know (haven't been in this codebase for a while) if we add something, but it really shouldn't add a content-type and/or content-length to get requests. Maybe it does, but that's a bug.
I am kinda in a time pressure here, so I guess I will swap from Fuel to something else. See it that will solve it. Otherwise if you have any other suggestion, it would be appreciated.
I personally won't be able to debug this right now, unfortunately. It's possible that this is Fuel; I would switch it out if that helps you right now. You can always come back to this :)
I swapped to kohttp, the problem is gone. If you want to further investigate the issue with Fuel I was using version 2.2.3
and then I swapped to the latest 2.3.0
. Both of them were buggy for me.
I will try to fork the C++ and see what is going on there. Sorry! and Thanks for the report! 🙇