curl refuses to fetch from HttpServer without --http0.9 #57

Closed
opened 2024-10-11 13:59:08 +00:00 by tobskep · 3 comments

I'm trying to rewrite one of my ongoing web projects in C using Cytoplasm. I've created an HTTP server and started it. It echoes the path requested back at the user.

I've noticed a problem with curl where if you don't pass the argument --http0.9, it refuses to download with the following message:

curl: (1) Received HTTP/0.9 when not allowed

When you pass --http0.9, it successfully fetches. What gives?

Here is the full program source, for debuggery:

void Handler(HttpServerContext *ctx, void *argv) {
    char* path = HttpRequestPath(ctx);
    Stream* out = HttpServerStream(ctx);

    HttpResponseStatus(ctx, HTTP_OK);
    HttpResponseHeader(ctx, "Content-type", "text/plain");
    StreamPrintf(out, "Everything is OK\nPath: %s\n", path);

    return;
}
int Main(Array *args, HashMap *envs) {
    // create HTTP server
    HttpServerConfig cfg = {
        6750,
        100,
        100,
        HTTP_FLAG_NONE,
        NULL, NULL,
        Handler,
        NULL
    };
    HttpServer *server = HttpServerCreate(&cfg);
    
    if (HttpServerStart(server) == false) {
        Log(LOG_ERR, "Failed to start HTTP server! (%s)", strerror(errno));
        return 1;
    } else {
        Log(LOG_INFO, "Started HTTP server on port %d.", cfg.port);
        HttpServerJoin(server);
        return 0;
    }
}
I'm trying to rewrite one of my ongoing web projects in C using Cytoplasm. I've created an HTTP server and started it. It echoes the path requested back at the user. I've noticed a problem with `curl` where if you don't pass the argument `--http0.9`, it refuses to download with the following message: ``` curl: (1) Received HTTP/0.9 when not allowed ``` When you pass `--http0.9`, it successfully fetches. What gives? Here is the full program source, for debuggery: ``` void Handler(HttpServerContext *ctx, void *argv) { char* path = HttpRequestPath(ctx); Stream* out = HttpServerStream(ctx); HttpResponseStatus(ctx, HTTP_OK); HttpResponseHeader(ctx, "Content-type", "text/plain"); StreamPrintf(out, "Everything is OK\nPath: %s\n", path); return; } int Main(Array *args, HashMap *envs) { // create HTTP server HttpServerConfig cfg = { 6750, 100, 100, HTTP_FLAG_NONE, NULL, NULL, Handler, NULL }; HttpServer *server = HttpServerCreate(&cfg); if (HttpServerStart(server) == false) { Log(LOG_ERR, "Failed to start HTTP server! (%s)", strerror(errno)); return 1; } else { Log(LOG_INFO, "Started HTTP server on port %d.", cfg.port); HttpServerJoin(server); return 0; } } ```
Author

Turns out it was my code. Still wouldn't mind knowing what caused that? That's a weird failure mode

Turns out it was my code. Still wouldn't mind knowing what caused that? That's a weird failure mode
Contributor

Still wouldn't mind knowing what caused that? That's a weird failure mode
Probably due to the fact you didnt call HttpSendHeaders (which caused curl to get really confused when it didnt get any data)
I think Cytoplasm should be made to warn/auto-send when that happens but you could argue that being able to use the stream directly the headers may be a nice-to-have

> Still wouldn't mind knowing what caused that? That's a weird failure mode Probably due to the fact you didnt call `HttpSendHeaders` (which caused curl to get *really* confused when it didnt get any data) I think Cytoplasm should be made to warn/auto-send when that happens but you could argue that being able to use the stream directly the headers may be a nice-to-have
Author

Could be a config feature

Could be a config feature
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Telodendria/Cytoplasm#57
No description provided.