http icon indicating copy to clipboard operation
http copied to clipboard

Bring `class ContentType` to `package:http`

Open ditman opened this issue 2 years ago • 12 comments
trafficstars

dart:io has a handy ContentType class that allows programmers to parse the content-type response header. Docs.

It'd be nice to have this class (and other HeaderValues) available through package:http, (or anywhere else outside of dart:io), so they can be used by flutter web.

ditman avatar Feb 03 '23 00:02 ditman

@brianquinlan Kindly please assign me this issue to solve it.

seifibrahim32 avatar Apr 14 '23 02:04 seifibrahim32

@seifibrahim32 What is your plan for fixing this?

brianquinlan avatar Apr 14 '23 18:04 brianquinlan

@brianquinlan

My plan is using SRP method for fixing this,

When I used to create Client with http , i saw that HTTPHeader class has content type parameter , for example

{
HttpHeader.contentType : "application/json charset=utf-8;"
}

The value we can utilise it by making HttpHeaderValue class this class is allowing users to make a ready one ,instead of making them put the value as a string type.

The class wil have static String parameters such as applicationJsonHTTP, applicationXMLHTTP,charsetUTF and et cetera..., these may equal to "application/json" or "application/xml" for XML , et cetera.

For better achievement for Single Responsibility Principle , we may make them an abstract super class called HeadersValue and we may make class extended from super for JSON and one for XML.

What will ease ? It will ease to achieve to make developer in the future as Web3 is in developing to add more featurea with ease.

It will ease to make things better easy for developers to work on. Ease to use Dart extensions

eg :

extension NewType on HeaderValue{
_//Place some code_
}

So, I would make the easy way :

//_EOL is the semicolon : end of line._
{
HttpHeader.contentType: HeaderValue.applicationJSONHTTP + HeaderValue.SPACE + HeaderValue.charsetValue.charsetUTF8 +HeaderValue.EOL
}

Or I would make concatenation for instance with add function return String type and the parameterType is dynamic accepts either pure String or List<HeaderValue>

{
HttpHeader.contentType: HeaderValue.add(HeaderValue.applicationJSONHTTP, HeaderValue.charsetValue.charsetUTF8,HeaderValue.signValue.EQUALS ,HeaderValue.EOL)
}

seifibrahim32 avatar Apr 14 '23 23:04 seifibrahim32

@seifibrahim32 I don't understand.

HttpHeader and HeaderValue are defined in dart:io and should not appear in the public interface of package:http.

In package:http the headers are represented using a map.

Content-Length is decoded separately so it may be possible to use a similar approach for Content-Type (and other common header values) except that the headers provided in the BaseResponse constructor can be used.

brianquinlan avatar Apr 20 '23 18:04 brianquinlan

@seifibrahim32 I don't understand.

HttpHeader and HeaderValue are defined in dart:io and should not appear in the public interface of package:http.

In package:http the headers are represented using a map.

Content-Length is decoded separately so it may be possible to use a similar approach for Content-Type (and other common header values) except that the headers provided in the BaseResponse constructor can be used.

So you mean we inject the HeaderValue class away from http, isn't correct?, or make the HeaderValue loosely coupled or we separate it from Http , right?

seifibrahim32 avatar Apr 20 '23 18:04 seifibrahim32

So you mean we inject the HeaderValue class away from http, isn't correct?, or make the HeaderValue loosely coupled or we separate it from Http , right?

We can't use the HeaderValue class defined in dart:io in package:http because it is can't be used in applications targeting the browser.

brianquinlan avatar Apr 20 '23 18:04 brianquinlan

So you mean we inject the HeaderValue class away from http, isn't correct?, or make the HeaderValue loosely coupled or we separate it from Http , right?

We can't use the HeaderValue class defined in dart:io in package:http because it is can't be used in applications targeting the browser.

Ok assign for me this task

seifibrahim32 avatar Apr 20 '23 18:04 seifibrahim32

@seifibrahim32 Do you still want to look at this issue?

brianquinlan avatar May 24 '23 18:05 brianquinlan

Hello I am back for figuring out this issue. @brianquinlan @ditman

seifibrahim32 avatar Apr 11 '24 22:04 seifibrahim32

@brianquinlan What about contributing to his package : https://github.com/dart-lang/sdk/tree/main/sdk/lib/html

and bring class ContentType from there also we can test the package through conformance tests?

or we prefer use package:web in replacement to dart:html?

seifibrahim32 avatar Apr 11 '24 23:04 seifibrahim32

I don't use dart:html anymore :)

ditman avatar Apr 12 '24 00:04 ditman

So we have to use package:web ?

If so do we need to add class Content-Type into our package:web?

Or we can add class Content-Type into _http internal package : https://github.com/dart-lang/sdk/tree/main/sdk/lib/_http ?

Or we can use it inside package:http package (not internal).?

seifibrahim32 avatar Apr 12 '24 00:04 seifibrahim32