File tree Expand file tree Collapse file tree 2 files changed +8
-2
lines changed
main/java/com/okta/commons/http
test/groovy/com/okta/commons/http Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -515,13 +515,14 @@ public Map<String, String> getLinkMap() {
515515 List <String > headerValues = headers .get (LINK );
516516 return headerValues .stream ()
517517 .map (HttpHeaders ::parseLinkHeader )
518+ .filter (link -> link != null )
518519 .collect (Collectors .toMap (Link ::getRelationType , Link ::getHref ));
519520 }
520521 return Collections .emptyMap ();
521522 }
522523
523524 private static Link parseLinkHeader (String rawHeader ) {
524- Pattern pattern = Pattern .compile ("\\ <(.*)\\ >;.*rel=\" (. *)\" " );
525+ Pattern pattern = Pattern .compile ("<(.*)>;.*rel=\" ?([^;|,| \" ] *)\" ?.* " );
525526 Matcher matcher = pattern .matcher (rawHeader );
526527 if (matcher .matches ()) {
527528 return new DefaultLink (matcher .group (2 ), matcher .group (1 ));
Original file line number Diff line number Diff line change @@ -413,11 +413,16 @@ class HttpHeadersTest {
413413 def headers = new HttpHeaders ()
414414 headers. add(" Link" , " <https://example.com/api/v1/users?limit=200>; rel=\" self\" " )
415415 headers. add(" Link" , " <https://dev-259824.oktapreview.com/api/v1/users?after=200u9wv2af0FYl791n0h7&limit=200>; rel=\" next\" " )
416+ headers. add(" Link" , " <meta.rdf>; rel=meta; as=meta" )
417+ headers. add(" Link" , " <random.link>;" )
418+ headers. add(" Link" , " <https://dev-259824.oktapreview.com/_sec/cp_challenge/sec-3-8.css>; as=style; rel=\" preload\" " )
416419
417420 def result = headers. getLinkMap()
418421 assertThat (result. get(" self" ), equalToObject(" https://example.com/api/v1/users?limit=200" ))
419422 assertThat (result. get(" next" ), equalToObject(" https://dev-259824.oktapreview.com/api/v1/users?after=200u9wv2af0FYl791n0h7&limit=200" ))
420- assertThat (result, aMapWithSize(2 ))
423+ assertThat (result. get(" meta" ), equalToObject(" meta.rdf" ))
424+ assertThat (result. get(" preload" ), equalToObject(" https://dev-259824.oktapreview.com/_sec/cp_challenge/sec-3-8.css" ))
425+ assertThat (result, aMapWithSize(4 ))
421426 }
422427
423428 @Test
You can’t perform that action at this time.
0 commit comments