Skip to content

reschke/structured-fields

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

291 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

structured-fields

A parser for the HTTP Structured Fields syntax defined in IETF RFC 9651.

Features

  • Parsing and Serialization
  • (Still) supports Java 8
  • Zero dependencies (except for tests)
  • Comprehensive parsing diagnostics

Links

Minimal Example

 {
     Parser p = new Parser("a=?0, b, c; foo=bar");
     Dictionary d = p.parseDictionary();
     for (Map.Entry<String, Item<? extends Object>> e : d.get()) {
         String key = e.getKey();
         Item<? extends Object> item = e.getValue();
         Object value = item.get();
         Parameters params = item.getParams();
         System.out.println(key + " -> " + value + (params.isEmpty() ? "" : (" (" + params.serialize() + ")")));
     }
 }

gives:

 a -> false
 b -> true
 c -> true (;foo=bar)

Testing Client

Here's a command line tool which will feed all arguments into the parser (as if obtained from multiple field lines), parsed as Item, List, or Dictionary:

$ java -jar target/structured-fields-0.6-SNAPSHOT.jar ':cHJldGVuZCB0aGlzIGlzIGJpbmFyeSBjb250ZW50Lg==:'  'x'

Item: >>:cHJldGVuZCB0aGlzIGlzIGJpbmFyeSBjb250ZW50Lg==:,x<<
        ----------------------------------------------^ (0x2c) Extra characters in string parsed as Item

List: :cHJldGVuZCB0aGlzIGlzIGJpbmFyeSBjb250ZW50Lg==:, x (OuterList)

Dict: >>:cHJldGVuZCB0aGlzIGlzIGJpbmFyeSBjb250ZW50Lg==:,x<<
        ^ (0x3a) Key must start with LCALPHA or '*': ':' (\u003a)

Status

This implementation is experimental and makes no promises yet on API stability (feedback on what might be missing is appreciated).

In the mid-term, this code might transition to the Apache HTTP Components project.

Maven Coordinates

<dependency>
  <groupId>org.greenbytes.http</groupId>
  <artifactId>structured-fields</artifactId>
  <version>0.5</version>
</dependency>

Java CI with Maven MvnRepository javadoc

About

Implementation of RFC 9651 ("Structured Field Values for HTTP")

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages