Serve Contact Downloads with the Right Headers

A contact-card link looks like a small feature until the response reaches a phone. The URL can be correct and the card contents can be valid, yet the browser may still treat the result differently from what the page suggests.
Recent work on a client contact-card plugin touched three parts of that path: serving the short link directly, keeping the intended MIME type and choosing a safe download filename. The client details aren’t needed to explain the change. The response behavior is the part worth taking into another project.
Follow the link all the way to its response
The plugin supports a file-like card path and an optional short path. The earlier short path redirected to the card URL. The later dispatch change sends the same saved card body from either address instead of adding that redirect.
That’s an important detail when reviewing a short link. Testing only that it points somewhere doesn’t tell you what headers or filename the person eventually receives. Check both entry paths and confirm whether the intended result is a redirect, a page or the contact file itself.
In this case, the route matcher still has an internal label inherited from the redirect behavior. The dispatcher is what determines the actual response. Reading only a helper name or an older test label would give the wrong account of the final implementation.
For your own integration, capture the status and headers from the complete route. A direct path working doesn’t establish that the short path behaves the same way.
Make the response type a deliberate choice
The plugin generates the card response in PHP rather than leaving the web server’s file-extension mapping to decide its type. Its header helper returns exactly text/vcard. The vCard specification registers that media type; it doesn’t guarantee the same import screen in every browser or contacts application.
The implementation also accounts for PHP’s default charset handling. It temporarily clears the setting while emitting the content type, then restores the previous value. PHP documents default_charset as affecting its default content-type behavior. A header assembled in application code can still be changed by runtime configuration.
The useful test here is the actual response value, including parameters. Looking at a source line that appears to set the right header is only the first step. A proxy, security layer or hosting configuration can add another change after PHP has done its work.
Keep this response-specific. A contact download doesn’t justify changing the default headers for every HTML page or unrelated file on the site.
Read the follow-up before prescribing a filename policy
One revision removed the file disposition while adjusting the phone response. A later revision deliberately restored an attachment disposition with the card’s sanitized .vcf filename. Reading the first patch alone would therefore produce an outdated recommendation.
The later helper normalizes the filename and falls back to contact.vcf when it can’t use the supplied value. That gives the short URL a useful filename even though the path itself doesn’t end in .vcf.
MDN’s Content-Disposition reference explains the difference between inline handling and attachment delivery. Treat the filename as response metadata, separate from the URL and the stored contact’s display name. Those values can serve different purposes.
The inspected tests expect the attachment filename and check the fallback for an unsuitable name. They don’t establish a universal rule about how every iPhone or Android device will open it. I’d describe the implemented download response and test devices separately, rather than promise automatic contact import from a header alone.
Test header construction and real delivery separately
The plugin has focused assertions for the exact MIME type, disposition and filename. They make accidental changes to the response helper easy to spot. It also removes inherited disposition and content-type-option headers before applying its selected card headers.
That last choice is specific to this feature. Don’t turn it into general advice to remove nosniff across a website. If another layer restores a header or changes the content type, investigate that response path and its requirements.
A helper test can’t see the final hosting stack. For an integration check, request both public paths, inspect the status and header values, and save the returned body. Compare its bytes and length with the intended card. Confirm that an ordinary GET receives the card rather than a theme page or an HTML error with a successful-looking URL.
Then use a small device matrix based on the project’s audience. Check the complete flow through opening, downloading and importing. Record what each device actually does; don’t infer that experience from a passing PHP assertion.
Keep public contact files narrow and predictable
The response retains a noindex instruction and uses the site’s no-cache helper. Neither makes a public contact card private. Only publish details that are intended to be shared, and keep private contact exports on a separate authorized path.
The body and its length also need to agree. The sender computes Content-Length from the body it will return. Unexpected output from another plugin or a warning can still spoil a generated file, which is another reason to inspect the delivered result.
The lesson from this change is fairly small: review the whole file response. A stable short address, a deliberate media type and a safe filename belong to the same feature. Keep their behavior covered without stretching a specific compatibility change into a promise about every phone.
Written by
Adrian Saycon
A developer with a passion for emerging technologies, Adrian Saycon focuses on transforming the latest tech trends into great, functional products.



