How to change default http protocol version from 0.9 to 1.1
I installed prometheus-cpp following instructions from Ubuntu apt. Seems like it only supports HTTP 0.9, because
curl http://127.0.0.1:9090/metrics
returns Received HTTP/0.9 when not allowed
and
curl --http0.9 http://127.0.0.1:9090/metrics works. Is there a way to use HTTP 1.1 protocol?
Hello,
I‘m puzzled because we explicitly write HTTP 1.1 versioned responses. Which Ubuntu version do you use?
Thanks, Gregor
Could you please run curl with -v and copy the headers of the failed request and response here?
Ubuntu 22.04.4 LTS.
curl -v http://127.0.0.1:9090/metrics
* Trying 127.0.0.1:9090...
* Connected to 127.0.0.1 (127.0.0.1) port 9090 (#0)
> GET /metrics HTTP/1.1
> Host: 127.0.0.1:9090
> User-Agent: curl/7.81.0
> Accept: */*
>
* Received HTTP/0.9 when not allowed
* Closing connection 0
curl: (1) Received HTTP/0.9 when not allowed
curl -v --http0.9 http://127.0.0.1:9090/metrics
* Trying 127.0.0.1:9090...
* Connected to 127.0.0.1 (127.0.0.1) port 9090 (#0)
> GET /metrics HTTP/1.1
> Host: 127.0.0.1:9090
> User-Agent: curl/7.81.0
> Accept: */*
>
# HELP exposer_transferred_bytes_total Transferred bytes to metrics services
# TYPE exposer_transferred_bytes_total counter
exposer_transferred_bytes_total 1612
# HELP exposer_scrapes_total Number of times metrics were scraped
# TYPE exposer_scrapes_total counter
exposer_scrapes_total 2
# HELP exposer_request_latencies Latencies of serving scrape requests, in microseconds
# TYPE exposer_request_latencies summary
exposer_request_latencies_count 2
exposer_request_latencies_sum 694
exposer_request_latencies{quantile="0.5"} 338
exposer_request_latencies{quantile="0.9"} 338
exposer_request_latencies{quantile="0.99"} 338
Could be related, I have also running mongoose webserver on different port in the same app. When I make curl request mongoose seems to be logging some stuff I dont understand:
57660acf 1 mongoose.c:2840:mg_iobuf_res 0->39041252766682
57660acf 1 mongoose.c:2840:mg_iobuf_res 0->39041252766682
Here is function in mongoose.c:
int mg_iobuf_resize(struct mg_iobuf *io, size_t new_size) {
int ok = 1;
new_size = roundup(new_size, io->align);
if (new_size == 0) {
mg_bzero(io->buf, io->size);
free(io->buf);
io->buf = NULL;
io->len = io->size = 0;
} else if (new_size != io->size) {
// NOTE(lsm): do not use realloc here. Use calloc/free only, to ease the
// porting to some obscure platforms like FreeRTOS
void *p = calloc(1, new_size);
if (p != NULL) {
size_t len = new_size < io->len ? new_size : io->len;
if (len > 0 && io->buf != NULL) memmove(p, io->buf, len);
mg_bzero(io->buf, io->size);
free(io->buf);
io->buf = (unsigned char *) p;
io->size = new_size;
} else {
ok = 0;
MG_ERROR(("%lld->%lld", (uint64_t) io->size, (uint64_t) new_size)); // 2840 line here
}
}
return ok;
}
I rebuilded my app without creating web server with mongoose, but still am having same log output from mongoose. This gave me suspicion that something smelly goes on in linking, so I completely removed mongoose dependency files from building process. And viola, curl works as it supposed to:
curl -v http://127.0.0.1:9090/metrics
* Trying 127.0.0.1:9090...
* Connected to 127.0.0.1 (127.0.0.1) port 9090 (#0)
> GET /metrics HTTP/1.1
> Host: 127.0.0.1:9090
> User-Agent: curl/7.81.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-Type: text/plain; charset=utf-8
< Content-Length: 804
<
So its definetely linking. But I need that web server on other port too..
I believe civetweb is a fork of mongoose. They share the same symbols and must not be mixed within a process.
I see. Is there any docs/example on how to make Exposer use different web server? Like mongoose in this case.