mootools/mootools-core — Issue #2201: When using method "HEAD" in Request, error occures
Author: complynx
Created: 2012-01-16 11:13:59+00:00
State: open

When using method "HEAD", it actually uses method "POST" instead.
If I use it when retrieving information about non-php files, server gets angry.
I think, Request needs "HEAD" support.

Changed Request.send from 1.4.2 (5214-5285 lines)

function(options){
if (!this.check(options)) return this;

this.options.isSuccess = this.options.isSuccess || this.isSuccess;
this.running = true;

var type = typeOf(options);
if (type == 'string' || type == 'element') options = {data: options};

var old = this.options;
options = Object.append({data: old.data, url: old.url, method: old.method}, options);
var data = options.data, url = String(options.url), method = options.method.toLowerCase();

switch (typeOf(data)){
case 'element': data = document.id(data).toQueryString(); break;
case 'object': case 'hash': data = Object.toQueryString(data);
}

if (this.options.format){
var format = 'format=' + this.options.format;
data = (data) ? format + '&' + data : format;
}

if (this.options.emulation && !['get', 'post', 'head'].contains(method)){
var _method = '_method=' + method;
data = (data) ? _method + '&' + data : _method;
method = 'post';
}

if (this.options.urlEncoded && ['post', 'put'].contains(method)){
var encoding = (this.options.encoding) ? '; charset=' + this.options.encoding : '';
this.headers['Content-type'] = 'application/x-www-form-urlencoded' + encoding;
}

if (!url) url = document.location.pathname;

var trimPosition = url.lastIndexOf('/');
if (trimPosition > -1 && (trimPosition = url.indexOf('#')) > -1) url = url.substr(0, trimPosition);

if (this.options.noCache)
url += (url.contains('?') ? '&' : '?') + String.uniqueID();

if (data && ['get', 'head'].contains(method)){
url += (url.contains('?') ? '&' : '?') + data;
data = null;
}

var xhr = this.xhr;
if (progressSupport){
xhr.onloadstart = this.loadstart.bind(this);
xhr.onprogress = this.progress.bind(this);
}

xhr.open(method.toUpperCase(), url, this.options.async, this.options.user, this.options.password);
if (this.options.user && 'withCredentials' in xhr) xhr.withCredentials = true;

xhr.onreadystatechange = this.onStateChange.bind(this);

Object.each(this.headers, function(value, key){
try {
xhr.setRequestHeader(key, value);
} catch (e){
this.fireEvent('exception', [key, value]);
}
}, this);

this.fireEvent('request');
xhr.send(data);
if (!this.options.async) this.onStateChange();
else if (this.options.timeout) this.timer = this.timeout.delay(this.options.timeout, this);
return this;
}
```