You use "if(request.indexOf('M-SEARCH') > 0) ..." this is false if 'M-SEARCH' is at the beginning of a string.
Use "if(request.indexOf('M-SEARCH') > -1)" instead.
There are other occurrences of this.
indexOf('M-SEARCH') only looks for 'M' and not for 'M-SEARCH'. Use "M-SEARCH" instead (with double quotes).
You use "if(request.indexOf('M-SEARCH') > 0) ..." this is false if 'M-SEARCH' is at the beginning of a string. Use "if(request.indexOf('M-SEARCH') > -1)" instead. There are other occurrences of this.
indexOf('M-SEARCH') only looks for 'M' and not for 'M-SEARCH'. Use "M-SEARCH" instead (with double quotes).