0

For an experiment purpose where I need to drop a specific content (audio data) coming from youtube in a HTTP response message, I am using below code.

Right now I am testing with specific video, and I know the size of the content. Ran some test without this code and captured the size variable.

if (contType.equals("text/plain") && contLen > 200000 && contLen < 300000) {
    outputFileName = projRoot + File.separator + folder + File.separator + "v_" + seqNum + "_" + String.valueOf(ranNum);

    log.debug("This is AUDIO data received, and dropping it off");
    response.setHeader("Content-Length", 0);
    response.getContent().clear();
    return true;
}

However when I run this program I see the log getting printed; however, it does not really drop the content. I see client (browser flash player) is still able to download the content, and this time with different size. The video is played with both visual and audio.

What is the correct way to drop off the content before it reaches the client? Am I missing on something here?

Anthony Accioly
  • 21,918
  • 9
  • 70
  • 118
AnilJ
  • 1,951
  • 2
  • 33
  • 60
  • What do you mean by "drop off"? You mean to prevent your data from being sent to the browser? I see nothing being written to the channel at this piece of code... Look for calls to `channel.write` and modify what is being written there. – Anthony Accioly Jul 10 '13 at 00:53
  • Correct. At this point in code, the data is already written/attached to the HTTP response message, which I am trying to clear. Yes, I am trying to prevent the data to reach the browser. If you are suggesting to control the channel.write, it means we have to do it at lower level in the proxy (I am using LittleProxy, which is implemented on top of netty). Is there any way to handle this at HTTP/proxy level? – AnilJ Jul 10 '13 at 02:54
  • Why would content marked text/plain be audio? What's the *real* problem here? – user207421 Jul 10 '13 at 04:49
  • It is youtube server which is sending the 'audio' with content type as "text/plain". In my use case, I need to strip off the audio information from the video before it reaches the client/browser. Note that Youtube server sends audio and video in two separate HTTP response messages. In my code above, I am trying to clear the HTTP response message, which contains the audio. – AnilJ Jul 10 '13 at 05:32

1 Answers1

1

Try:

HttpHeaders.setContentLength(response, 0l);
response.setContent(null); 

Also make sure that your browser is not loading the content from the local cache.

I'm not sure that you can use LittleProxy to intercept and change the response like that... Although this thread suggests that you can do so using a HttpFilter (check this test code for the basic structure). Otherwise you will have to dig into Little Proxy source code for further customization.

Anthony Accioly
  • 21,918
  • 9
  • 70
  • 118