Skip to content

Commit e9536b8

Browse files
committed
A few tweaks mentioned by the AI.
1 parent fff69d1 commit e9536b8

4 files changed

Lines changed: 24 additions & 18 deletions

File tree

src/Gotenberg.Sharp.Api.Client/Domain/Builders/Faceted/HtmlConversionBehaviorBuilder.cs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ 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+
3742
_htmlConversionBehaviors.WaitDelay = $"{seconds}s";
3843

3944
return this;
@@ -78,21 +83,6 @@ public HtmlConversionBehaviorBuilder SetUserAgent(string userAgent)
7883
return this;
7984
}
8085

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-
9686
/// <summary>
9787
/// Sets extra HTTP headers that Chromium will send when loading the HTML
9888
/// </summary>

src/Gotenberg.Sharp.Api.Client/Domain/Builders/Faceted/HtmlConversionBehaviorBuilderExtensions.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16+
using Newtonsoft.Json.Linq;
17+
1618
namespace Gotenberg.Sharp.API.Client.Domain.Builders.Faceted;
1719

1820
public static class HtmlConversionBehaviorBuilderExtensions
@@ -83,4 +85,18 @@ public static HtmlConversionBehaviorBuilder AddCookies(this HtmlConversionBehavi
8385

8486
return builder;
8587
}
88+
89+
/// <summary>
90+
/// Sets extra HTTP headers that Chromium will send when loading the HTML
91+
/// </summary>
92+
/// <param name="builder">HtmlConversionBehaviorBuilder</param>
93+
/// <param name="headerName"></param>
94+
/// <param name="headerValue"></param>
95+
/// <returns></returns>
96+
/// <exception cref="InvalidOperationException"></exception>
97+
/// <exception cref="JsonReaderException"></exception>
98+
public static HtmlConversionBehaviorBuilder AddAdditionalHeaders(this HtmlConversionBehaviorBuilder builder, string headerName, string headerValue)
99+
{
100+
return builder.AddAdditionalHeaders(new JObject { [headerName] = headerValue });
101+
}
86102
}

src/Gotenberg.Sharp.Api.Client/Domain/Builders/Faceted/WebhookBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ public WebhookBuilder SetErrorUrl( Uri url, HttpMethod? method = null)
7979

8080
public WebhookBuilder AddExtraHeader(string name, string value)
8181
{
82-
return this.AddExtraHeader(name, new[] { value });
82+
return this.AddExtraHeader(name, [value]);
8383
}
8484

8585

8686
public WebhookBuilder AddExtraHeader(KeyValuePair<string, string> header)
8787
{
88-
return this.AddExtraHeader(header.Key, new[] { header.Value });
88+
return this.AddExtraHeader(header.Key, [header.Value]);
8989
}
9090

9191

src/Gotenberg.Sharp.Api.Client/Infrastructure/Constants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public static class Html
211211
public static class Shared
212212
{
213213
/// <summary>
214-
/// From the header & footer tabs
214+
/// From the header &amp; footer tabs
215215
/// </summary>
216216
public static class FileNames
217217
{

0 commit comments

Comments
 (0)