Response code is coming as 000 in the access log while using NginxJavaRingHandler

1,270 views
Skip to first unread message

Subha Ramesh

unread,
May 19, 2016, 3:21:57 AM5/19/16
to Nginx-Clojure
Hi,

  In my nginx-clojure service, which is very much similar to the sample code mentioned here (https://github.com/nginx-clojure/nginx-clojure/blob/master/test/java/nginx/clojure/java/StreamingWriteHandler.java),

 I am getting the response HTTP status code as 000 (instead of 200) for all my GET calls in the nginx access log.  But the call is successful and I am able to download the content (size 2 MB) from nginx server.

I tried to fix this issue by using the sendHeader method in NginxHttpServerChannel instead of doing this way in the sample code ,

resp_headers = ("HTTP/1.1 200 OK\r\n" + "Date: Wed, 08 Jul 2015 07:12:26 GMT\r\n" + "Content-Type: text/plain\r\n" + "Content-Length: "+large_content_for_demo.length+"\r\n" +"\r\n").getBytes();


But then I am getting the error ("Response does not start with HTTP" ) when I try to do a GET call from fiddler.

Has anyone come across this issue before? Can someone help me fix the status code issue in access log.

Thanks,
Subha

Subha Ramesh

unread,
May 19, 2016, 3:25:36 AM5/19/16
to Nginx-Clojure
I am using nginx-clojure 0.4.3 version.

Yuexiang Zhang

unread,
May 19, 2016, 8:39:10 AM5/19/16
to Subha Ramesh, Nginx-Clojure
Hi,

Please use this line  

//make access log have correct http status
NginxClojureRT.pushNGXInt(((NginxJavaRequest) request).nativeRequest() + MiniConstants.NGX_HTTP_CLOJURE_REQ_HEADERS_OUT_OFFSET
+ MiniConstants.NGX_HTTP_CLOJURE_HEADERSO_STATUS_OFFSET, 200);


Regards.
xfeep


--
You received this message because you are subscribed to the Google Groups "Nginx-Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nginx-clojur...@googlegroups.com.
To post to this group, send email to nginx-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nginx-clojure/983923b3-ada5-4749-943d-a6c68b0330fe%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Subha Ramesh

unread,
May 25, 2016, 1:33:39 AM5/25/16
to Nginx-Clojure, subh...@gmail.com
Hi, 

 Thanks for the solution. It worked. But in case of sendtimeout also I am getting the response code as 200. Could you please tell me the way to return a different response code (408) in case of send timeout?

Thanks,
Subha

Yuexiang Zhang

unread,
May 25, 2016, 11:56:10 AM5/25/16
to Subha Ramesh, Nginx-Clojure
Hi,

Did you mean http status need set to be 408 at access log when send timeout happens?
If it is YES please try the below method changeReponseHttpStatus  when send timeout happends

public void changeReponseHttpStatus(NginxRequest request, int code) {
long statusAddr = request.nativeRequest() 
+ MiniConstants.NGX_HTTP_CLOJURE_REQ_HEADERS_OUT_OFFSET
+ MiniConstants.NGX_HTTP_CLOJURE_HEADERSO_STATUS_OFFSET;

NginxClojureRT.pushNGXInt(statusAddr,  code);
}

e.g.

changeReponseHttpStatus(request, 200); //initialize http status to 200
ch.addListener(ch, new ChannelCloseAdapter<NginxHttpServerChannel>() {
@Override
public void onClose(NginxHttpServerChannel data) throws IOException {
log.info("StreamingWriteHandler closed now!");
}
@Override
public void onWrite(long status, NginxHttpServerChannel ch) throws IOException {
if (status < 0) {
log.error("onWrite error %s", NginxClojureAsynSocket.errorCodeToString(status));
if (status == NginxClojureAsynSocket.NGX_HTTP_CLOJURE_SOCKET_ERR_WRITE_TIMEOUT) 
    //make access log use 408 as the http status for this request 
    changeReponseHttpStatus(ch.request(), 408);
}
ch.close();
}else {
doWrite(ch);
}
}
});



Regards.
xfeep

Subha Ramesh

unread,
May 25, 2016, 11:18:49 PM5/25/16
to Nginx-Clojure, subh...@gmail.com
Hi,

 This is exactly what I was looking for. Worked fine. Thank you very much.
Reply all
Reply to author
Forward
0 new messages