This is my twelve week in AESTE. Continue fixing some minor bugs for my JQuery with Wt and many studying and planning for my PCB design.

Getting Started with having SERVER sending request to CLIENT

First I change my ‘CUSTOM’ request into ‘HEAD’ request, and have my SERVER (PIC32 in this case) able to send a header to my CLIENT (Wt in this case). The concept is really simple and the method to achieve it is also very easy, however the protocol must be correct!

  • For CORS protocol there is always a preflight request send for custom header (in other words an OPTION request will be send follow by other requests)
  • The rule to make sure a ‘header’ being send from SERVER to CLIENT using a browser (Mozilla or Chrome), SERVER side must respond with “Access-Control-Expose-Headers: CustomHeader”
  • The important thing is that this ‘Access-Control-Expose-Headers’ command must be responded by the SERVER to CLIENT every single time (every request) to allow the content of ‘CustomHeader’ to be access by CLIENT and allowed by Mozilla and Chrome.
  • A simple example:

    //During an OPTION request SERVER can respond so
    “HTTP/1.1 200 Ok\r\n”
    “Access-Control-Allow-Origin: * \r\n”
    “Access-Control-Allow-Methods: PUT, DELETE, HEAD \r\n”
    “Access-Control-Allow-Headers: yourHeader\r\n”

  • //Follow by other requests eg: PUT, DELETE or HEAD
    “HTTP/1.1 200 Ok\r\n””Access-Control-Allow-Origin: * \r\n”
    “Access-Control-Expose-Headers: CustomHeader\r\n”
    “CustomHeader: blablabla.\r\n”

  • From the above example, during the 2nd request (PUT, DELETE or HEAD), the content of ‘CustomHeader’ which is ‘blablabla’ will be send to CLIENT
  • Then from the CLIENT side :
  • //for JQuery Ajax
    .done(function(data, status, xhr){
    console.log( “CustomHeader: ” + xhr.getResponseHeader(“CustomHeader”));

  • By doing so, JQuery with ‘getResponseHeader’ function will be able to get the content of ‘CustomHeader’ and parse/process the data, which is ‘blablabla’ in this case.
  • This flow of SERVER respond to CLIENT request is a really simple step but very strict!, any mismatch of words/contents neither side will respond correctly and a ‘null’ will be output for ‘CustomHeader’ if any mistakes was made.

Next I did some blog digging, where I studied previous interns’ work regarding PCB design. I study the reasoning behind their pin connection and did some planning for my design. The PCB design that I am going to do for the following week is using a PIC32MZ MCU and Spartan 6 FPGA.

Luckily I have a really good reference source to study for my PIC32 with Spartan 6. And this week end with me doing many planning for my MCU pin mapping. I need to make sure that the MCU I am using is able to incorporate all the features that I was assign to implement. If not shit might get real along the road if I made a mistake right at the start. Looking forward to next week, with fun schematic drawing and PCB design~


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.