Jump to content

Recommended Posts

I'm thinking about having Http_Header ValueObjects.

 

Motivation:

 

1. Ensure that headers are valid

2. Simplify setting of headers by providing a set (and documented) list of available headers when editing.

 

So I set off and created a Http_Header class. And I was pretty pleased with the simplicity and elegance of it (aside from the long winded names). A Header object is created pretty simply:

 

$header = new Backbone_Http_Header_Response(Backbone_Http_Header_Response::H_TESTHEADER, "test");

 

Obviously it doesn't check if the value of the header is valid (other than that it's a string), but I'm not so sure I even want to implement that.

 

What I'm doing is the following:

 

a) For easy editing, I declare all the possible headers as constants, and assign codes to them (borrowed from http://msdn2.microsoft.com/en_us/library/ms537417.aspx).

b) To be able to check if a header name is valid, I use reflection to create a static associative array of header names, indexed by code.

c) To fetch the name of a Header instance, lookup the instance's header code in the static array.

 

Backbone_Http_Header lists header names valid for both responses and requests, subclasses Backbone_Http_Header_Response and *_Request headers specific to a respectively a request or a response.

 

Anyway, the reason for my post: isn't there some sort of build-in functionality that can accomplish this? I get the feeling that I am reinventing the wheel...  :(

Link to comment
https://forums.phpfreaks.com/topic/51795-http-headers/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.