Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
692 views
in Technique[技术] by (71.8m points)

rest - Is HTTP status code 426 Upgrade Required only meant signal an upgrade to a secure channel is required?

I have a mobile device communicating via HTTPS to a RESTful API on my servers. One of the operations is a data sync to push modifications made while offline to the server and pull down updates made in parallel on the server.

I've encountered an edge case where that sync operation can fail silently in the existing client. I've upgraded the "sync protocol" on the client to handle the condition properly. Ideally I'd like to have all older clients receive a message when they try to sync telling them to upgrade.

The communication is just between my server and my mobile client so I realize I can return any number of HTTP codes and signal the client to display a message in the future advising the user to upgrade and to immediately stop the sync process.

Would it be seen as a bastardization of the intent of the HTTP 426 Upgrade Required return code to use it to signal this. Every reference (IETF RFC 2817, Wikipedia) I can find speaks to using it to signal a client to upgrade to TLS. Is it meant to be limited to well defined/security protocols like SSL and TLS or is it a generic upgrade flag at the HTTP layer which has only been used for SSL and TLS traditionally?

If it isn't intended for this use case would a HTTP 303 See Other be considered more appropriate or is there another code I'm missing?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Quoting one of my previous answers:

HTTP Upgrade is used to indicate a preference or requirement to switch to a different version of HTTP or to another protocol, if possible:

The Upgrade general-header allows the client to specify what 
additional communication protocols it supports and would like to use 
if the server finds it appropriate to switch protocols. The server 
MUST use the Upgrade header field within a 101 (Switching Protocols) 
response to indicate which protocol(s) are being switched.

      Upgrade        = "Upgrade" ":" 1#product

  For example,

     Upgrade: HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11

The Upgrade header field is intended to provide a simple mechanism 
for transition from HTTP/1.1 to some other, incompatible protocol.

According to the IANA register, there are only 3 registered mentions of it (including one in the HTTP specification itself).

The other two are for:

(The IANA register hasn't changed since then.)

The 426 response code as defined in RFC 2817 clearly has to do with an upgrade in the "HTTP Upgrade" sense defined in RFC 2816. This is a change of the current protocol at the layer currently used (i.e. HTTP itself). (It's not even about upgrading from http:// to https:// at all.)

The messages exchanged on top of HTTP (if part of a protocol at all) are not part of this. They're just hypermedia entities as far as HTTP is concerned.

I don't think 426 would be suitable if you change the meaning of your hypermedia. A plain 400 would probably be a better choice. Note that responses with error status codes (4xx, 5xx) do not prevent you from associating an entity in the response: this is where a message telling the client to upgrade your protocol (at that level) should be.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...