0

I am running the netty http upload example and have one additional requirement that to authentication before upload files; i understand that to upload big files we are using multipart mode to upload, and the server side will read POST request by multiple times.

So my idea is that set token in the request body as first parameter, and when reading chunks I can firstly verify the token ,if does not match cancel the whole request and return some status code to client side.

The point is that how can i cancel the request and send status code appropriately, I had tried like below, but when the channel have closed, the client did not finished sending the request, and will throw "connection reset" exception:

ChannelFuture future = channel.writeAndFlush(response);
future.addListener(ChannelFutureListener.CLOSE);

How to send response back to client during manually reading chunked post msg. In my case send response and close channel when the chunk is not the last chunk ,client side could not get any response.

raul
  • 73
  • 5

1 Answers1

1

I think the way you're doing is correct, but note that, according to the following item found on answering before the full request is received is possible but not really supported by most of the browsers:

Is it acceptable for a server to send a HTTP response before the entire request has been received?

If the client is you own, have you any log that shows a message is coming back before the connection reset? Have you the ability to send the answer from the server at the first message, before any chunk (so based on headers only) (it might help perhaps) ?

Community
  • 1
  • 1
Frederic Brégier
  • 2,108
  • 1
  • 18
  • 25
  • Thanks Frederic for your quick answer, your answer is quit help for me; yes, i tried most popular browsers but netty client can get the response before throw "connection reset" exceptionguess that i have to handler this by my own , – raul Nov 20 '14 at 11:10
  • You could also on server side consume quickly all chunks up to last one, by just throwing them (so no multipart task at all) when you find out in the header part that it has not to be handled. Then when the last chunk arrives, you send your error answer back and close the channel. – Frederic Brégier Nov 20 '14 at 11:13
  • Thanks again Frederic, I had try that but the file is quit big and it will cost much time. – raul Nov 20 '14 at 11:29