I want to implement Options method in my HTTP web server. But I didn't yet find the good tutorial of the working of this method. I made one code that implements this method, my code is at the end of this question.
But I think the working of server I used is wrong. Can you tell me the exact method/ steps how server respond, when it gets Options request. Waiting for you kind response.
Client Code
public class Client {
public static void main(String[] args) {
HttpClient client = new HttpClient();
client.getParams().setParameter("http.useragent", "Test Client");
OptionsMethod method = new OptionsMethod("http://localhost:8080");
try {
int returnCode = client.executeMethod(method);
if(returnCode == 405 ) {
System.out.println("The Options method is not implemented by this URI");
} else {
Header[] header = method.getResponseHeaders();
for(int i = 0; i < header.length; i++) {
System.out.println(header[i].getName() + ": " + header[i].getValue());
}
}
} catch(Exception e) {
System.out.println("Options method ki to TAI TAI FISSHHHHHH");
} finally {
System.out.println("close method");
method.releaseConnection();
}
}
}
Server Code (my server allows PUT, POST, GET, HEAD, OPTIONS methods)
printStream.print("HTTP/1.1 200 OK");
printStream.write(Worker.EOL);
printStream.print("Date: " + new Date());
printStream.write(Worker.EOL);
printStream.print("Allow: OPTIONS, GET, HEAD, POST, PUT");
printStream.write(Worker.EOL);
printStream.print("Content-Length: 0");
printStream.write(Worker.EOL);
printStream.write(Worker.EOL);
Is this a correct way to respond by the server? If not please tell me the server working when it gets Options Request ?