GitHub Classroom says 404 to HEAD request

Dear Forum,

Using a classical Java HTTP client library (Jersey), I get a 404 status sent back to me when sending a HEAD request to the URL https://classroom.github.com/a/mgecjMoT. The URL corresponds to an assignment that exists. A GET request returns the expected 200 status.

Using curl yields the expected 200 status, for both HEAD (-I) and GET requests.

Why does GitHub classroom return a 404 status in some cases for a HEAD request on a URL that exists? Could anyone investigate?

Here is the Java code, for the readers who would wonder.

Invocation.Builder request = ClientBuilder.newClient().target(“https://classroom.github.com/a/mgecjMoT”).request();
LOGGER.info(“Requesting.”);
LOGGER.info(“Using GET: {}.”, request.get());
LOGGER.info(“Using HEAD: {}.”, request.head());

And the result is as follows.

00:17:10.187 [main] INFO i.g.o.check_links_from_source.App - Requesting.
00:17:37.004 [main] INFO i.g.o.check_links_from_source.App - Using GET: InboundJaxrsResponse{context=ClientResponse{method=GET, uri=https://classroom.github.com/a/mgecjMoT, status=200, reason=OK}}.
00:17:48.815 [main] INFO i.g.o.check_links_from_source.App - Using HEAD: InboundJaxrsResponse{context=ClientResponse{method=HEAD, uri=https://classroom.github.com/a/mgecjMoT, status=404, reason=Not Found}}.

Same behavior when changing the user agent used by the client to “curl” or to “curl/7.55.1”.

Stupid me. The difference is that the Java library follows redirects. It does see the 302 status, then (several redirects) ends up at a login page, to which it tries to send empty information, which ends up as a 404 (I have not investigated the exact reason). Whereas curl, by default, does not follow redirects and is thus happy with a 302. Adding -L to curl also yields a 404.

Incidentally, curl receives a 302, not a 200, for a HEAD request, as expected.

So this was a PEBCAK.