Showing posts with label HTTP. Show all posts
Showing posts with label HTTP. Show all posts

Generate HTML form data in VBscript

Sometimes you have to post form data in an AJAX call started from server-side ASP script (or WSH script). The following VBScript functions will return well-formed form data that you can use with the application/x-www-form-urlencoded MIME type:

Function URLEncoded(V) ' … private
  Dim CC,I,Enc
  Enc = ""

  For I = 1 To Len(V)
    CC = AscW(Mid(V,I,1))
    If (CC >= 48 And CC < 58) Or (CC >= 64 And CC < 90) Or (CC >= 97 And CC < 124) Or CC = 95 Or CC = 45 Or CC = 46 Then
      Enc = Enc & Mid(V,I,1)
    Else
      Enc = Enc & "%" & Hex(CC)
    End If
  Next
  URLEncoded = Enc
End Function

Function CreateFormField(F,V) ' … private
  CreateFormField = F & "=" & URLEncoded(CStr(V))
End Function  

'
' EncodeFormData: Return form data for a POST request
'
' Input: N – array of form field names
'        V – array of form field values
'
' Return: encoded form data
'
Function EncodeFormData(N,V)
  Dim I
  For I = LBound(N) To UBound(N)
    If I <> LBound(N) Then EncodeFormData = EncodeFormData & "&"
    EncodeFormData = EncodeFormData & CreateFormField(N(I),V(I))
  Next
End Function

Yahoo is not totally HTTP compliant ... what else is new?

An article in Cisco's support wiki caught my attention today: it claims that Cisco routers could deny access to yahoo.com because Yahoo!'s web servers emit invalid chunked encoding. Interesting ... so I've started Fiddler and opened Yahoo!'s home page. This is what I've got:
HTTP/1.1 200 OK
Date: Sun, 14 Sep 2008 13:42:11 GMT
P3P: policyref="http://p3p.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV"
Cache-Control: private
Vary: User-Agent
Set-Cookie: IU=deleted; expires=Sat, 15 Sep 2007 13:42:10 GMT; path=/; domain=.yahoo.com
Set-Cookie: FPCM=deleted; expires=Sat, 15 Sep 2007 13:42:10 GMT; path=/
Set-Cookie: D=_ylh=X3oDMTFkbmtlMG9nBF9TAzI3MTYxNDkEcGlkAzEyMjEzOTczMjEEdGVzdAMwBHRtcGwDaW5kZXgtbA--; path=/; domain=.yahoo.com
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8
Content-Encoding: gzip

7b17   
As you can see there are actually three blanks after the chunk length, which is a clear violation of section 3.6.1 of RFC 2616 (HTTP); the chunk length should be followed by semicolon (for chunk extensions) or CRLF. I'm not really surprised; the crappy implementation of Frontpage extensions on Geocities (and the fact that they wanted to charge me for it) pushed me toward my own web site six years ago.

Testing Your Website in a Realistic Environment (InformIT article)

My last website performance related article published by InformIT, Testing Your Website in a Realistic Environment, deals with an interesting question: "assuming you've fixed most of the performance problems your web site had, how can you test what your global visitors experience without buying a round-the-world ticket?"

Fix Your Web Site Performance Problems (InformIT article)

If you've realized that you might have HTTP-related performance problems when reading my Why is my web site so slow article published by InformIT, you can find a variety of quick fixes and more permanent solutions in my Fix Your Web Site Performance Problems article (also published by InformIT).

Why is my web site so slow (InformIT article)

If you've been involved in more than a few website deployments, I'm positive that you've encountered the following scenario: The website was developed, tested, demonstrated to internal audiences, accepted, deployed, …and failed completely due to unacceptable performance. In my InformIT article Why is my web site so slow I'm describing various reasons that can cause unacceptable performance for global visitors of your web.

Analyze your web page peformance

Straight from the Yahoo Developer Network: YSlow analyzes any web page and generates a grade for each rule and an overall grade. If a page can be improved, YSlow lists the specific changes to be made. Highly recommended tool :)

Back to the future?

In his blog post, Steve Souders describes how IE8 increases the page download performance by using more than two parallel HTTP sessions, briefly mentioning that this violates the recommendation from RFC 2616, which was, after all, written in 1999.

Some web developers might be too young to remember why RFC 2616 has the "two parallel sessions" recommendations. It was (among other reasons) a result of the disasters an earlier version of Internet Explorer (IE3?) caused on the Web infrastructure when Microsoft in its infinite wisdom decided to open multiple parallel HTTP sessions. The browsers quickly overloaded WAN links, caused server overloads (if you use 6 parallel sessions instead of two, all of a sudden the number of "visitors" increases three-fold), firewall failures (some firewalls had licenses limiting the number of parallel sessions) and potentially NAT failures (if you have to do port-address-translation, you might run out of port numbers).

But it looks like the history needs to repeat itself ... or maybe this time the infrastructure is ready for the additional load? My "what could fail" bet would be on the servers, but we'll see in a few months ...

Web caching, Part 3: Database Integration

The last article in my Web caching series published by InformIT.com details the database integration methods. As most SQL databases don't give you record modification timestamps, you have to implement them yourself. In this article, you'll see how you can use SQL triggers to implement table-level, record-level and join-level timestamps that can be used to set the last-modified date on an HTTP response.

Web Caching, Part 2: Reduce the Download Time

In my second article in the Web caching series published by InformIT.com, I've focused on caching dynamically generated pages in the browser cache. The article explains the in-depth details of browser-side HTTP caching and the HTTP headers you have to process in server scripts to make your dynamic pages cacheable.

When properly implemented, this solution can drastically reduce the amount of information downloaded to visitor's browser, thus increasing the overall responsiveness of your web application.

Web Caching, Part 1: Explicit Content Expiration

InformIT.com has published Reap the Benefits of Web Caching, Part 1: Explicit Content Expiration; the first article in my three-part series covering usage of web caching mechanisms in dynamic web pages.