0

I'm writing a http handling library and now dealing with reduction. I'm a little confused about the response code 301, it said that when 301 happens, it is allowed to change the request method from POST to GET.

Since POST method contains bodies while GET doesn't, how could I resend the original POST request to the new location with GET, without losing bodies?

And why the protocol allow this changing, any particularly reason?

psionic12
  • 185
  • 1
  • 11
  • A 301 is indicative of a permanent change of one URL to another. It's simply a way of informing the caller that the destination address should be permanently changed to somewhere else. Where the new destination accepts `POST` or `GET` is really up to them, but if the previously destination accepted a `POST` then the replacement destination _should_ too. Complex payloads cannot be included in the `GET` request as you already are aware. – Martin May 14 '21 at 07:27
  • @psionic12 — Answering that bit likely requires guessing what the people who wrote the spec decades ago were thinking, which isn't really possible. – Quentin May 14 '21 at 07:31
  • So in practice, is it okay that my lib just re-send the request as what ever it is, not consider the change thing? – psionic12 May 14 '21 at 07:36
  • 1
    @psionic12 I would suggest that if the original end-point accepted `POST` and returns a `301`, that the new end-point _should_ also accept `POST`. It would be better if they were returning a `308` though which doesn't permit the method to change – Martin May 14 '21 at 07:38
  • By the way the fact that GET request cannot contain a body is not clearly stated in RFC, and some http servers support bodies in GET requests. – regilero May 14 '21 at 08:20
  • @regilero Ref: https://stackoverflow.com/a/983458/2169762. You can send a payload with the `GET` but it may be discarded or ignored by the server before delivered to the end software – Martin May 14 '21 at 09:19

0 Answers0