Showing posts with label Request. Show all posts
Showing posts with label Request. Show all posts

Tuesday, April 08, 2008

HTTP request and response headers examples using telnet

yu$ telnet www.google.com 80
Trying 64.233.189.99...
Connected to www.l.google.com.
Escape character is '^]'.
GET /intl/en_ALL/images/logo.gif HTTP/1.1
Host: www.google.com
User-Agent: Mozilla/5.0(Robots) Gecko/20061206 Firefox/1.5.0.9
Accept-Encoding: gzip,deflate

HTTP/1.1 200 OK
Content-Type: image/gif
Last-Modified: Wed, 07 Jun 2006 19:38:24 GMT
Expires: Sun, 17 Jan 2038 19:14:07 GMT
Server: gws
Content-Length: 8558
Age: 13
Date: Sun, 06 Apr 2008 06:51:56 GMT

GIF89an.....

yu$ telnet www.google.com 80
Trying 64.233.189.104...
Connected to www.l.google.com.
Escape character is '^]'.
GET /intl/en_ALL/images/logo.gif HTTP/1.1
Host: www.google.com
User-Agent: Mozilla/5.0(Robots) Gecko/20061206 Firefox/1.5.0.9
Accept-Encoding: gzip,deflate
If-Modified-Since: Wed, 07 Jun 2006 19:38:24 GMT

HTTP/1.1 304 Not Modified
Date: Sun, 06 Apr 2008 06:53:10 GMT
Server: GFE/1.3

yu$ telnet l.yimg.com 80
Trying 203.209.246.249...
Connected to geoycs-l.yahoo8.akadns.net.
Escape character is '^]'.
GET /a/i/ww/news/2008/04/04/crocodile-sm.jpg HTTP/1.1
Host: l.yimg.com
User-Agent: Mozilla/5.0(Robots) Gecko/20061206 Firefox/1.5.0.9
Accept-Encoding: gzip,deflate
Connection: keep-alive

HTTP/1.1 200 OK
Date: Sat, 05 Apr 2008 00:14:27 GMT
Cache-Control: max-age=315360000
Expires: Tue, 03 Apr 2018 00:14:27 GMT
Last-Modified: Fri, 04 Apr 2008 17:49:26 GMT
Accept-Ranges: bytes
Content-Length: 860
Content-Type: image/jpeg
Age: 133250
Connection: keep-alive
Server: YTS/1.16.0



Connection closed by foreign host.

In HTTP/1.1 the ETag and If-None-Match headers are another way to make conditional GET requests.

<IMG ALT="Red Star"
SRC="data:image/gif;base64,R0lGODlhDAAMALMLAPN8ffBiYvWW
lvrKy/FvcPewsO9VVfajo+w6O/zl5estLv/8/AAAAAAAAAAAAAAAACH5BAEA
AAsALAAAAAAMAAwAAAQzcElZyryTEHyTUgknHd9xGV+qKsYirKkwDYiKDBia
tt2H1KBLQRFIJAIKywRgmhwAIlEEADs=">

Friday, August 24, 2007

Rails controller request and response methods and instance_variables


class TestController < ApplicationController
before_filter { |controller| p controller.request.methods.sort; p controller.request.instance_variables }
after_filter { |controller| p controller.response.methods.sort; p controller.response.instance_variables }

def index
end
end


# ["==", "===", "=~", "__id__", "__send__", "`", "accepts", "b64encode", "blank?", "cgi", "cgi=", "class", "clone", "content_type", "cookies", "copy_instance_variables_from", "daemonize", "dclone", "decode64", "decode_b", "delete?", "display", "domain", "dup", "enable_warnings", "encode64", "env", "eql?", "equal?", "extend", "extend_with_included_modules_from", "extended_by", "formatted_post?", "freeze", "frozen?", "gem", "get?", "hash", "head?", "host", "host_with_port", "id", "inspect", "instance_eval", "instance_exec", "instance_of?", "instance_values", "instance_variable_get", "instance_variable_set", "instance_variables", "is_a?", "kind_of?", "load", "method", "method_missing", "methods", "nil?", "object_id", "parameters", "path", "path_parameters", "path_parameters=", "port", "port_string", "post?", "post_format", "pretty_inspect", "pretty_print", "pretty_print_cycle", "pretty_print_inspect", "pretty_print_instance_variables", "private_methods", "protected_methods", "protocol", "public_methods", "put?", "query_parameters", "query_string", "raw_post", "relative_url_root", "relative_url_root=", "remote_ip", "remove_subclasses_of", "request_parameters", "request_uri", "require", "require_gem", "require_library_or_gem", "reset_session", "respond_to?", "returning", "send", "server_software", "session", "session=", "session_options", "session_options=", "silence_stderr", "silence_stream", "silence_warnings", "singleton_methods", "ssl?", "standard_port", "subclasses_of", "subdomains", "suppress", "symbolized_path_parameters", "taguri", "taguri=", "taint", "tainted?", "to_a", "to_json", "to_param", "to_s", "to_yaml", "to_yaml_properties", "to_yaml_style", "type", "unloadable", "untaint", "with_options", "xhr?", "xml_http_request?", "xml_post?", "yaml_post?"]
# ["@session", "@request_method", "@query_parameters", "@parameters", "@content_type", "@request_parameters", "@session_options", "@session_options_with_string_keys", "@symbolized_path_parameters", "@env", "@cgi", "@path_parameters"]
# ["==", "===", "=~", "__id__", "__send__", "`", "assigns", "assigns=", "b64encode", "blank?", "body", "body=", "charset", "charset=", "class", "clone", "content_type", "content_type=", "cookies", "cookies=", "copy_instance_variables_from", "daemonize", "dclone", "decode64", "decode_b", "display", "dup", "enable_warnings", "encode64", "eql?", "equal?", "extend", "extend_with_included_modules_from", "extended_by", "freeze", "frozen?", "gem", "hash", "headers", "headers=", "id", "inspect", "instance_eval", "instance_exec", "instance_of?", "instance_values", "instance_variable_get", "instance_variable_set", "instance_variables", "is_a?", "kind_of?", "layout", "layout=", "load", "method", "methods", "nil?", "object_id", "out", "pretty_inspect", "pretty_print", "pretty_print_cycle", "pretty_print_inspect", "pretty_print_instance_variables", "private_methods", "protected_methods", "public_methods", "redirect", "redirected_to", "redirected_to=", "redirected_to_method_params", "redirected_to_method_params=", "remove_subclasses_of", "require", "require_gem", "require_library_or_gem", "respond_to?", "returning", "send", "session", "session=", "silence_stderr", "silence_stream", "silence_warnings", "singleton_methods", "subclasses_of", "suppress", "taguri", "taguri=", "taint", "tainted?", "template", "template=", "to_a", "to_json", "to_param", "to_s", "to_yaml", "to_yaml_properties", "to_yaml_style", "type", "unloadable", "untaint", "with_options"]
# ["@session", "@headers", "@assigns", "@body", "@redirected_to", "@cgi", "@template"]

Sunday, August 05, 2007

prototype javascript library ajax example


<div id="ajax_div">
use ajax to update it!
</div>
<br/>
<div id="ajax_failure">
if evalScript set false, sayHi is not defined!
</div>

<input type="button" name="button_ajax" value="ajax update div" id="button_ajax" />

<script type="text/javascript" charset="utf-8">
function doc(argument) {
document.write("<p>\n");
document.write(argument);
document.write("</p>\n");
}
var url = '/prototype/ajax_eval_script';
var options = {
method: 'get',
evalScripts: true,
parameters: 'id=1',
insertion: Insertion.Top
}

//new Ajax.Updater('ajax_div', url, options);
//new Ajax.Request(url, {onComplete: function (req) { alert(req.responseText); }});
var ajax = new Ajax.Request();
doc('ajax.transport type is ' + ajax.transport); //ajax.transport = Ajax.getTransport();
new Ajax.Updater({success: 'ajax_div', failure: 'ajax_failure'}, url, options);

ajax.setOptions(Object.extend(options, {onComplete: function(req) {
$('ajax_div').innerHTML = req + "<br/>\n" +
"req == ajax.transport is " + (req == ajax.transport) + "<br/>\n" +
"Server is " + req.getResponseHeader('Server') + "<br/>\n" +
"ajax request status is " + ajax.transport.status + "<br/>\n";
}
}));
$('button_ajax').onclick = function (event) { ajax.request('/prototype/ajax_eval_script'); };
</script>

/prototype/ajax_eval_script

<script language="javascript" type="text/javascript">
//function sayHi(){ // do nothing, function is not generated in runtime
//var sayHi = function(){ // not use the "var" keyword
sayHi = function(){
alert('Hi');
}
</script>

<input type="button" value="Click Me" onclick="sayHi()"/>
Note that in the previous example we did not use the var keyword to declare the variable. Doing so would have created a function object that would be local to the script block (at least in IE and FireFox). Without the var keyword the function object is scoped to the window, which is our intent.