HTTP/1.0 response to HTTP/1.1 request - http

Is it alright to respond with HTTP/1.0 to HTTP/1.1 request?
I am implementing HTTP communication through simple sockets and clients make requests with both HTTP/1.0 and HTTP/1.1 but protocol is independent of HTTP version so I want to always respond with HTTP/1.0 to all requests.
Does HTTP standard bear such communication?

Of course it's alright. Otherwise, if you only supported HTTP/1.0, what could you do?
If HTTP 1.2 came out today, what do you think all existing HTTP 1.1 servers would send as replies to HTTP 1.2 queries? Of course, it'll have to be HTTP 1.1 replies -- that's all they know how to do.
Just make sure you don't follow HTTP 1.1 rules where they differ. For example, keep alives are not enabled by default. If a client sees an HTTP 1.0 reply, it will assume HTTP 1.0 semantics.

Related

Can you see HTTPS in curl response?

I may be lacking in HTTP and HTTPS knowledge so apologies in advance.
I see that in the response to a curl request, using curl -i, we can see the HTTP version and response code, for e.g. HTTP/2 200. This is returned when the curl request is directed at a HTTPS endpoint (https://xxx).
Would it be possible to see a HTTPS in the response? If not, why not?
No, whether the communication is secure or not has nothing to do with which version of the protocol you are using, in the response you will see the version (commonly HTTP/1.1 or HTTP/2 these days)
Using https means that the connection is established over TLS, while the communication protocol is still HTTP.
In simple terms, TLS is a communication channel, while HTTP is a dialect

http1.1 Keep-Alive without pipelining

I'm implementing a server that is sending to the client a http keep-alive request but I would like that the client does not make pipelining requests. Is there any flag to tell client to not do multiple pipeline requests?
The keep-alive request seams to work but I don't want pipeline requests.
I would like a sequential request.
No, there is no such flag.
FWIW, with pipelining the requests would still be sequential, you just can get more while still sending a response.

How to know if a server supports HTTP 1.0

I need to know if a server supports HTTP 1.0. I send this message through a TCP socket:
GET / HTTP/1.0
Host: www.example.com
The thing is that in sometimes I get a HTTP 1.0 response and other times HTTP 1.1 response. How should I interpret this responses?
Thanks!
I need to know if a server supports HTTP 1.0.
When you send the request GET / HTTP/1.0 you're telling the server that the HTTP version you as a client support is 1.0.
If a server is either designed for HTTP 1.0 or designed for HTTP 1.1 with backwards compability to 1.0 then the server should send a 1.0 response to a 1.0 request, not a 1.1 response since the response might not be supported by the client.
In the HTTP protocol, the client is expected to send the version with the request, before it has any idea about what the server is or does.
That means that your trial-and-error approach is probably the only way to tell.
In practice, HTTP/1.0 isn't really in use the vast majority of the time, and it's almost always appropriate to use HTTP/1.1.

How does a HTTP 1.1 server respond to a HTTP 1.0 request?

How does HTTP 1.1 server should respond to a HTTP 1.0 request for headers like Pragma : no-cache which are supported in HTTP 1.0 but not in HTTP 1.1
If we assume that the HTTP 1.1 server wants to be backward compatible with HTTP 1.0 clients, then the HTTP 1.1 server would send a HTTP 1.0 response to HTTP 1.0 clients.
For example, let's assume that your HTTP 1.0 client sends a request like this:
GET /path/to/resource HTTP/1.0
Notice that the last part of the request is "HTTP/1.0", indicating the client's supported HTTP version. We'll get back to this, but it's important.
Your HTTP 1.1 server might normally want to use the Cache-Control response header to disable any caching, e.g.:
HTTP/1.1 200 OK
Cache-Control: no-cache
But Cache-Control is not supported for HTTP 1.0 requests, and the above response indicates that it is an HTTP 1.1 response, which is odd, given the HTTP 1.0 request.
So instead, the HTTP 1.1 server would have to generate an HTTP 1.0 compliant response, like so:
HTTP/1.0 200 OK
Pragma: no-cache
The HTTP 1.1 server ideally pays attention to the HTTP version in the request, and constructs a response that is appropriate for that HTTP version. For an older client (.e.g. HTTP 1.0) communicating with a newer, backward-compatible server (e.g. HTTP 1.1), this works.
What happens, though, if it's a newer client talking to an older server, such as an HTTP 1.1 client talking to an HTTP 1.0 server? In that case, the request might be:
GET /path/to/resource HTTP/1.1
Host: example.com
Cache-Control: no-cache
The HTTP 1.0 server won't know about the Cache-Control header, or any other HTTP 1.1-isms. In this case, the HTTP 1.0 server might reject the response using "400 Bad Request" (or some other similar non-success response code) because of the version incompatibility, or the server might issue an HTTP 1.0 response to the HTTP 1.1 request:
HTTP/1.0 200 OK
Pragma: no-cache
The actual behavior you see will depend on the client and server implementations involved.
Hope this helps!

How does a HTTP 1.0 only server respond to a HTTP 1.1 request?

Fairly simple question (I think). If a client sends a message like GET /whatever HTTP/1.1 to a server that only supports HTTP 1.0, how does the server react? What are the rules for header fields added in HTTP 1.1 that a HTTP 1.0 server doesn't recognise? Does the server simply ignore 1.1 requests, ignore headers it doesn't understand, return an error, or something else?
HTTP/1.0 200 OK
All headers of HTTP/1.1 (that a HTTP 1.0 server doesn't recognise) will be ignored.

Resources