Share cookies between subdomain and domain

If you set a cookie like this: Set-Cookie: name=value then the cookie will only apply to the request domain, and will only be sent for requests to the exact same domain, not any other subdomains. (See What is a host only cookie?) Two different domains (e.g. example.com and subdomain.example.com, or sub1.example.com and sub2.example.com) can only … Read more

Correctly switching between HTTP and HTTPS using .htaccess

I use something similar to this for my admin folder in wordpress: #redirect all https traffic to http, unless it is pointed at /checkout RewriteCond %{HTTPS} on RewriteCond %{REQUEST_URI} !^/checkout/?.*$ RewriteRule ^(.*)$ http://mydomain.com/$1 [R=301,L] The RewriteCond %{HTTPS} on portion may not work for all web servers. My webhost requires RewriteCond %{HTTP:X-Forwarded-SSL} on, for instance. If … Read more

ASP.NET MVC – HTTP Authentication Prompt

Well, to require basic authentication you need to return 401 status code. But doing that will cause the current authentication module to execute its default unauthorized handler (for forms authentication, this means redirecting to login page). I wrote an ActionFilterAttribte to see if I can get the behaviour you want when there’s no authentication module … Read more

Send FormData with other field in AngularJS

Don’t serialize FormData with POSTing to server. Do this: this.uploadFileToUrl = function(file, title, text, uploadUrl){ var payload = new FormData(); payload.append(“title”, title); payload.append(‘text’, text); payload.append(‘file’, file); return $http({ url: uploadUrl, method: ‘POST’, data: payload, //assign content-type as undefined, the browser //will assign the correct boundary for us headers: { ‘Content-Type’: undefined}, //prevents serializing payload. don’t … Read more

Programmatically reading a web page

Have a look at the cURL library: #include <stdio.h> #include <curl/curl.h> int main(void) { CURL *curl; CURLcode res; curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, “curl.haxx.se”); res = curl_easy_perform(curl); /* always cleanup */ curl_easy_cleanup(curl); } return 0; } BTW, if C++ is not strictly required. I encourage you to try C# or Java. It is … Read more

Chunked encoding and content-length header

No: “Messages MUST NOT include both a Content-Length header field and a non-identity transfer-coding. If the message does include a non-identity transfer-coding, the Content-Length MUST be ignored.” (RFC 2616, Section 4.4) And no, you can use Content-Length and stream; the protocol doesn’t constrain how your implementation works.