@@ -34,11 +34,6 @@ internal HtmlConversionBehaviorBuilder(HtmlConversionBehaviors htmlConversionBeh
3434 /// <remarks>Prefer <see cref="SetBrowserWaitExpression" /> over waitDelay.</remarks>
3535 public HtmlConversionBehaviorBuilder SetBrowserWaitDelay ( int seconds )
3636 {
37- if ( seconds < 0 )
38- {
39- throw new ArgumentOutOfRangeException ( nameof ( seconds ) , "Wait delay must be zero or positive." ) ;
40- }
41-
4237 _htmlConversionBehaviors . WaitDelay = $ "{ seconds } s";
4338
4439 return this ;
@@ -56,7 +51,7 @@ public HtmlConversionBehaviorBuilder SetBrowserWaitExpression(string expression)
5651 {
5752 if ( expression . IsNotSet ( ) )
5853 {
59- throw new ArgumentException ( "expression cannot be null or empty" , nameof ( expression ) ) ;
54+ throw new InvalidOperationException ( "expression is not set" ) ;
6055 }
6156
6257 _htmlConversionBehaviors . WaitForExpression = expression ;
@@ -75,14 +70,29 @@ public HtmlConversionBehaviorBuilder SetUserAgent(string userAgent)
7570 {
7671 if ( userAgent . IsNotSet ( ) )
7772 {
78- throw new ArgumentException ( "userAgent cannot be null or empty" , nameof ( userAgent ) ) ;
73+ throw new InvalidOperationException ( "headerName is not set" ) ;
7974 }
8075
8176 _htmlConversionBehaviors . UserAgent = userAgent ;
8277
8378 return this ;
8479 }
8580
81+ /// <summary>
82+ /// Sets extra HTTP headers that Chromium will send when loading the HTML
83+ /// </summary>
84+ /// <param name="headerName"></param>
85+ /// <param name="headerValue"></param>
86+ /// <returns></returns>
87+ /// <exception cref="InvalidOperationException"></exception>
88+ /// <exception cref="JsonReaderException"></exception>
89+ public HtmlConversionBehaviorBuilder AddAdditionalHeaders ( string headerName , string headerValue )
90+ {
91+ var header = string . Format ( "{0}{2}{1}" , "{" , "}" , $ "{ '"' } { headerName } { '"' } : { '"' } { headerValue } { '"' } ") ;
92+
93+ return AddAdditionalHeaders ( JObject . Parse ( header ) ) ;
94+ }
95+
8696 /// <summary>
8797 /// Sets extra HTTP headers that Chromium will send when loading the HTML
8898 /// </summary>
@@ -93,7 +103,7 @@ public HtmlConversionBehaviorBuilder AddAdditionalHeaders(JObject extraHeaders)
93103 {
94104 if ( extraHeaders == null )
95105 {
96- throw new ArgumentNullException ( nameof ( extraHeaders ) ) ;
106+ throw new InvalidOperationException ( " extraHeaders is null" ) ;
97107 }
98108
99109 _htmlConversionBehaviors . ExtraHeaders = extraHeaders ;
@@ -132,11 +142,6 @@ public HtmlConversionBehaviorBuilder AddCookie(Cookie cookie)
132142 /// <returns></returns>
133143 public HtmlConversionBehaviorBuilder SetMetadata ( IDictionary < string , object > dictionary )
134144 {
135- if ( dictionary == null )
136- {
137- throw new ArgumentNullException ( nameof ( dictionary ) ) ;
138- }
139-
140145 SetMetadata ( JObject . FromObject ( dictionary ) ) ;
141146
142147 return this ;
@@ -153,7 +158,7 @@ public HtmlConversionBehaviorBuilder SetMetadata(JObject metadata)
153158 {
154159 if ( metadata == null )
155160 {
156- throw new ArgumentNullException ( nameof ( metadata ) ) ;
161+ throw new InvalidOperationException ( " metadata is null" ) ;
157162 }
158163
159164 _htmlConversionBehaviors . MetaData = metadata ;
@@ -204,7 +209,7 @@ public HtmlConversionBehaviorBuilder SetPdfFormat(ConversionPdfFormats format)
204209 {
205210 if ( format == default )
206211 {
207- throw new ArgumentOutOfRangeException ( nameof ( format ) , "Invalid PDF format specified" ) ;
212+ throw new InvalidOperationException ( "Invalid PDF format specified" ) ;
208213 }
209214
210215 _htmlConversionBehaviors . PdfFormat = format ;
0 commit comments