Reputation: 23
I am trying to make a Java web server that will compare the if-modified-since with the file's last modified. However, I don't know how to get the if-modified-since header from the client and do the comparison.
Upvotes: 0
Views: 353
Reputation: 362087
I wouldn't jump right into trying to handle a particular header. If you're writing a web server from scratch then you should write a generic HTTP parser that can handle every part of an HTTP request:
GET
, POST
, etc.)Name: Value
You could, for instance, build up a class like:
class HttpRequest {
String method;
URL url;
String httpVersion;
Map<String, String> headers;
byte[] body;
}
Since header names are case insensitive I'd suggest using map with String.CASE_INSENSITIVE_ORDER
.
Once you can parse all headers than looking for a particular header will be a simple task. If you had the class above it'd be as easy as looking up headers.get("If-Modified-Since")
.
Upvotes: 1