public static Tpl <Urls, Future <Either <ConfigFetchError, WWWWithHeaders> > > withTimeout( this Tpl <Urls, Future <Either <ConfigFetchError, WWWWithHeaders> > > tpl, Duration timeout, ITimeContext timeContext = default(ITimeContext) ) { timeContext = timeContext.orDefault(); return(tpl.map2((urls, future) => future .timeout(timeout, () => (ConfigFetchError) new ConfigTimeoutError(urls, timeout), timeContext) .map(e => e.flatten()) )); }
public static Tpl <Urls, Future <Either <ConfigFetchError, WWWWithHeaders> > > checkingContentType( this Tpl <Urls, Future <Either <ConfigFetchError, WWWWithHeaders> > > tpl, string expectedContentType = "application/json" ) => tpl.map2((urls, future) => future.map(wwwE => wwwE.flatMapRight(headers => { var contentType = headers["CONTENT-TYPE"].getOrElse("undefined"); // Sometimes we get redirected to internet paygate, which returns HTML // instead of our content. if (contentType != expectedContentType) { return(Either <ConfigFetchError, WWWWithHeaders> .Left( new ConfigWrongContentType(urls, expectedContentType, contentType) )); } return(wwwE); })) );
public static Tpl <Urls, Future <Either <ConfigFetchError, WWWWithHeaders> > > checkingServerHeader( this Tpl <Urls, Future <Either <ConfigFetchError, WWWWithHeaders> > > tpl, string headerName, string expectedValue ) => tpl.map2((urls, future) => future.map(wwwE => { var headersOpt = wwwE.fold( err => F.opt(err as ConfigWWWError).map(_ => _.wwwWithHeaders), _ => _.some() ); return(headersOpt.fold( wwwE, headers => { var actual = headers[headerName]; return actual.exists(expectedValue) ? wwwE : Either <ConfigFetchError, WWWWithHeaders> .Left(new ConfigServerCheckFailed( urls, headerName, expectedValue, actual )); } )); }) );