Friday, 17 March 2017

koa - Wrong http status message when piping response from remote server

I have server A and server B. The client requests a file from server A, and server A gets the file from server B. This works fine when the client requests a file that exists, but the client receives the wrong http status message when requesting a file that doesn't exist.

Problem:

The client receives "404 OK" in the status line when it should be "404 Not Found". No matter what status code I send, the status message is always 'OK', but the client does always receive the status code I set (301, 402, etc). Also, Server A does receive the correct status message, and for whatever reason, server A seems to propagate the status code, but not the message.

Server A code:

import request from 'request'

context.response.body = request( my_url );

//request( my_url, (error, response, body) =>
//{
//   console.log( "message: " + response.statusMessage );  //prints 'Not Found'
//});

Server B code:

context.response.status = 404; 
context.response.message = 'Not Found';
context.response.body = 'Page not found';

What am I doing wrong?



via Kacy

No comments:

Post a Comment