Graceful shutdown of a node.JS HTTP server

You can control the idle timeout for a connection, so you can set how long a keep-alive connection will remain open. For example: server=require(‘http’).createServer(function(req,res) { //Respond if(req.url.match(/^\/end.*/)) { server.close(); res.writeHead(200,{‘Content-Type’:’text/plain’}); res.end(‘Closedown’); } else { res.writeHead(200,{‘Content-Type’:’text/plain’}); res.end(‘Hello World!’); } }).listen(1088); //Set the idle timeout on any new connection server.addListener(“connection”,function(stream) { stream.setTimeout(4000); }); We can test this … Read more

Is Content-Type mandatory in HTTP post request?

No, it’s not mandatory. Per the HTTP 1.1 specification: Any HTTP/1.1 message containing an entity-body SHOULD include a Content-Type header field defining the media type of that body. If and only if the media type is not given by a Content-Type field, the recipient MAY attempt to guess the media type via inspection of its … Read more

Really logging the POST request body (instead of “-“) with nginx

Nginx doesn’t parse the client request body unless it really needs to, so it usually does not fill the $request_body variable. The exceptions are when: it sends the request to a proxy, or a fastcgi server. So you really need to either add the proxy_pass or fastcgi_pass directives to your block. The easiest way is … Read more

In golang, how to determine the final URL after a series of redirects?

package main import ( “fmt” “log” “net/http” ) func main() { resp, err := http.Get(“http://stackoverflow.com/q/16784419/727643”) if err != nil { log.Fatalf(“http.Get => %v”, err.Error()) } // Your magic function. The Request in the Response is the last URL the // client tried to access. finalURL := resp.Request.URL.String() fmt.Printf(“The URL you ended up at is: %v\n”, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)