Coder Social home page Coder Social logo

dart-lang / http_parser Goto Github PK

View Code? Open in Web Editor NEW
36.0 38.0 26.0 187 KB

A platform-independent Dart package for parsing and serializing HTTP formats.

Home Page: https://pub.dev/packages/http_parser

License: BSD 3-Clause "New" or "Revised" License

Dart 100.00%

http_parser's Introduction

Build Status Pub Package package publisher

http_parser is a platform-independent package for parsing and serializing various HTTP-related formats. It's designed to be usable on both the browser and the server, and thus avoids referencing any types from dart:io or dart:html.

Features

  • Support for parsing and formatting dates according to HTTP/1.1, the HTTP/1.1 standard.

  • A MediaType class that represents an HTTP media type, as used in Accept and Content-Type headers. This class supports both parsing and formatting media types according to HTTP/1.1.

  • A WebSocketChannel class that provides a StreamChannel interface for both the client and server sides of the WebSocket protocol independently of any specific server implementation.

http_parser's People

Contributors

athomas avatar bcko avatar chalin avatar dependabot[bot] avatar devoncarew avatar franklinyow avatar jakemac53 avatar keertip avatar kevmoo avatar lrhn avatar natebosch avatar nex3 avatar sigurdm avatar srawlins avatar whesse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

http_parser's Issues

Exception when content-type contains colon

Testing versions:

4.0.2 and c14fbf

Steps to Reproduce:

  1. Find any instance of diaspora*, Mobilizon, Pleroma, Akkoma, Funkwhale or WriteFreely (you can use Fediverse Observer)
  2. Open https://<instance>/.well-known/nodeinfo
  3. Take any link with href key and try to load it via http package

Expected Result:

Just a response

Actual Result:

E/flutter ( 4133): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Error on line 1, column 31: Invalid media type: expected no more input.
E/flutter ( 4133):   ╷
E/flutter ( 4133): 1 │ application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.0#; charset=utf-8
E/flutter ( 4133):   │                               ^
E/flutter ( 4133):   ╵
E/flutter ( 4133): #0      wrapFormatException (package:http_parser/src/utils.dart:15:5)
E/flutter ( 4133): #1      new MediaType.parse (package:http_parser/src/media_type.dart:46:7)
E/flutter ( 4133): #2      _contentTypeForHeaders (package:http/src/response.dart:79:45)
E/flutter ( 4133): #3      _encodingForHeaders (package:http/src/response.dart:72:24)
E/flutter ( 4133): #4      Response.body (package:http/src/response.dart:28:22)

Error in http_parser with dart 3.4

Running flutter pub run build_runner build --output=build

yields

[WARNING] ../../../../.pub-cache/hosted/pub.dev/http_parser-4.0.2/lib/src/case_insensitive_map.dart:10:37: Error: The class 'CanonicalizedMap' can't be extended outside of its library because it's a final class.
class CaseInsensitiveMap<V> extends CanonicalizedMap<String, String, V> {

Unhandled exception thrown when access some specific Urls

Exception:

Unhandled exception:
Error on line 1, column 33: Invalid media type: expected /[^()<>@,;:"\\\/[\]?={} \t\x00-\x1F\x7F]+/.
application/json; charset=utf-8;
                                ^
#0      wrapFormatException (package:http_parser/src/utils.dart:15:5)
#1      new MediaType.parse (package:http_parser/src/media_type.dart:46:12)
#2      _contentTypeForHeaders (package:http/src/response.dart:93:39)
#3      _encodingForHeaders (package:http/src/response.dart:86:22)
#4      Response.body (package:http/src/response.dart:27:22)

Code to reproduce this exception:

import 'package:http/http.dart' as http;

main()  {
  _doRequest();
}

void _doRequest() async {
  final response = await http.get("http://image.baidu.com/data/imgs?col=%e7%be%8e%e5%a5%b3&tag=%e5%b0%8f%e6%b8%85%e6%96%b0&sort=0&pn=10&rn=10&p=channel&from=1");

}

Error parsing mime-type with trailing semicolon

I detected and error trying to read this RSS https://status.slack.com/feed/rss

this is the error

Unhandled exception:
Error on line 1, column 25: Invalid media type: expected /[^()<>@,;:"\\/[\]?={} \t\x00-\x1F\x7F]+/.
  ╷
1 │ text/xml; charset=UTF-8;
  │                         ^
  ╵
#0      wrapFormatException (package:http_parser/src/utils.dart:15:5)
#1      new MediaType.parse (package:http_parser/src/media_type.dart:46:7)
#2      _contentTypeForHeaders (package:http/src/response.dart:85:45)
#3      _encodingForHeaders (package:http/src/response.dart:78:24)
#4      Response.body (package:http/src/response.dart:28:22)
#5      updateContent (package:test_rss/test_rss.dart:71:26)
<asynchronous suspension>

and this is a Dart pad test case, but doesn't show all the error message.

https://dartpad.dev/?id=d42c08d17403e34b7a3441e4ff9bfa09

import 'package:http/http.dart' as http;
void main() async {
  final url = Uri.parse('https://status.slack.com/feed/rss');
  final response = await http.get(url);
  print(response.body);
}

Could you add `tryParse` to `MediaType`

Hi.

this types has tryParse option

int.tryParse(source)
double.tryParse(source)
DateTime.tryParse(formattedString)

It would be nice to have the same for MediaType

DataUri class conflicts with UriData added to dart:core

In the bleeding-edge version of the SDK, there is a UriData class added to dart:core which conflicts with the one added here. So there is an analyzer error for the DataUri.data member, since Uri has added a .data member of type UriData.

So this needs to be fixed, or http_parser needs to be rolled back in the SDK.

1.0 tag doesn't work in DEPS

In all other packages I've been able to depend on specific commit hashes via git tags, for example, '@0.10.0'. However for the http_parser repository the 1.0.0 tag doesn't work. I'm not sure why but git complains about it not being a "tree".

Default charset for "application/json" incorrect

When a response is received with the Content-Type header set to "application/json" (without specifying the charset) the parser incorrectly assumes the response to be encoded as ISO-8859-1 (Latin-1)
The comments in the code refer to document RFC-2616 and incorrectly concludes the default encoding must be Latin-1. While the RFC indeed mentions a Latin-1 default encoding it does so only for text responses. No default is assumed for any other media type.

On the other hand, the IANA document describing the "application/json" mediatype (https://www.iana.org/assignments/media-types/application/json) says in its final note:
No "charset" parameter is defined for this registration.
Adding one really has no effect on compliant recipients.

It is therefore correct not to add "charset=utf-8" to the "application/json" Content-Type header.

Finally, RFC-8259 says explicitly that JSON code should always be considered as being Unicode encoded, commonly in UTF-8 format.

Hence from all the above, the correct default charset for "application/json" mediatype must be "utf-8" whether the charset is present or not in the content-type header.
This same reasoning is likely applicable to other mediatype but I didn't research any further.

Consider making MediaType a compile-time constant

I'm working on a code-gen package to improve the UX of creating backend apps. One of the primary use cases is to register acceptable MediaTypes for a given endpoint, and map it to a body parser. Since MediaType is not a compile-time constant, I'm unable to achieve the following:

@BodyParser({MediaType.multipartForm})
UserDto userFromForm(List<int> data) => _$UserFromForm

Would we be willing to reconsider looking into this issue or accept a PR?

My workaround for the time being will be to create my own MediaType class, but I'd ideally like to not fragment from popular packages like this one.

http_parser should support more time zones than GMT

<img src="https://avatars.githubusercontent.com/u/17034?v=3" align="left" width="96" height="96"hspace="10"> Issue by kevmoo
Originally opened as dart-lang/sdk#18739


Per http://freesoft.org/CIE/RFC/1123/99.htm

There is a strong trend towards the use of numeric timezone indicators, and implementations SHOULD use numeric timezones instead of timezone names. However, all implementations MUST accept either notation. If timezone names are used, they MUST be exactly as defined in RFC-822.

transformResponse take too long

Screenshot 2022-12-19 at 16 45 04

Due to JSON decode take 40.5ms on main isolate hence create a UI jank.
Maybe we can move the decode function to a background isolate using the compute function?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.