The curious case of missing Authorization header

I have been wasting time on a small issue adding Authorization header into HttpClient.

The code was plain and simple:

Specifically, I was writing a .NET Core console app, following this wiki page https://github.com/projectkudu/kudu/wiki/Accessing-the-kudu-service and trying to access http://mysite.scm.azurewebsites.net/basicauth. However, I kept getting 401 Unauthorize response and response.RequestMessage.Headers was completely empty.

After having spent some time searching for solution on the Internet but to no avail, I opened Fiddler to see the actual HTTP requests. Turns out, this was what happened behind the scene:

There were actually 2 requests. The first one has the Authorization header and returns a 302 Found. Automatic redirection of HttpClient triggers the second request, and this one didn’t have any Authorization header.

Normally I can just stop there, accept that how things work in .NET and find a workaround. But since .NET Core is open source on GitHub, I decided to dig a bit deeper to understand the reason of this implementation. A quick search about redirection on the corefx repo in GitHub gave me the exact commit that I need: https://github.com/dotnet/corefx/commit/e8a17715fba4ba6cfce4043a2cd117474dfcee05. And voila, I could see the line in RedirectHandler.cs that causing the issue:

and I could also see the reason in SocketsHttpHandler.cs:

 

I finally solved my curious case, and I hope this post is useful to you. Feel free to leave me a comment and let me know if you have any suggestion on securely implement the redirection with Authorization header.

 

How to integrate Teamcity and GitLab CI

I note down the step I did to integrate TeamCity build server and GitLab CI pipeline. I am using TeamCity 2017.1.15 and GitLab 10.0.3.

What you will get with this integration:

  • Small green tick for each commit showing that a build has run successfully on the commit
  • Bigger tick for each merge request (MR) showing that a build has run successfully on the head of the merge request
  • Ability to enforce a successful build before any MR can be merged

How to set up the integration

Tldr, you need to go through 3 main steps:

  1. Enable TeamCity integration in your GitLab project settings
  2. Enable TeamCity build configuration to monitor and trigger build for all (CI) branches
  3. Enable “Commit status publisher” build feature

Read More

Building a small running bot with Windows 10 on a Raspberry Pi 2

I won a Raspberry Pi B+ from a Microsoft event, so I took some time to learn about the Pi to understand more about all the fuzz around IoT. The experience I had is very fun and excited. I study and work mainly on software engineering, so hacking the virtual world is much more familiar to me that hacking those hardware and devices in the real world. However, Raspberry Pi turned out to be the perfect device for me to learn more about this IoT area by providing a bridge between high level programming language (such as Python) and all the “complicated” GPIO and I2C stuffs. In other words, you can write Python instead of C++ or Assembly to communicate with so many electrical boards and devices. There are many interesting and easy to follow tutorials on Adafruit that I strongly recommend you to take a look and give it a try.

With the introduction of Windows 10 on Raspberry Pi 2, the small computing box becomes even more interesting to me. The Pi can now run Universal Windows apps and communicate with devices such as Xbox controller. Therefore, I have decided to buy a new Pi 2 and give Windows 10 IoT a try with a new project: a running robot that is remotely controlled with a Xbox Controller.
Read More

Beta8 and the new hosting model

In ASP.NET6 beta8, Helios (IIS native host) has been removed. Instead you can use Kestrel host and configure IIS server to talk to the host. This hosting model should be very familiar with people using ASP.NET 6 on Linux as they may have already been using this hosting model from previous betas. I won’t write much about the hosting model as Damian Edwards already has a detailed post on that here: https://github.com/aspnet/Announcements/issues/69
However, I will describe some change that everyone that are using Helios on Windows would have to make to their beta7 projects.
Read More

CompositeTransform3D in Windows 10

I believe this has been mentioned in several blog posts (such as this one), but I missed one important part, and it took me almost an hour to figure out why my CompositeTransform3D does not give a nice 3D effect but only a “scaling” effect.

Turn out I need to have to put a PerspectiveTransform3D in the container of the element with CompositeTransform3D.