Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StatusCode is defined as integer (string is not possible) #380

Closed
hsnsalhi opened this issue Nov 29, 2019 · 12 comments
Closed

StatusCode is defined as integer (string is not possible) #380

hsnsalhi opened this issue Nov 29, 2019 · 12 comments
Labels

Comments

@hsnsalhi
Copy link

hsnsalhi commented Nov 29, 2019

Hello,
I want to extract the status code from url but the mapping json is skipped because StatusCode can't be as string.
This is an example of what I want to do:

{
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "RegexMatcher",
            "Pattern": "/test/(\\d+)"
          }
        ]
      },
      "Methods": [
        "post"
      ]
    },
    "Response": {
      "StatusCode": "{{Regex.Match request.url \"\\d+\"}}",
      "BodyAsJson": {
        "path": "{{request.path}}"
      },
      "UseTransformer": true
    }
  }
@StefH
Copy link
Collaborator

StefH commented Nov 29, 2019

According to HTTP specification, I think it's only allowed to use a number between 100 and 599 as status code.

@StefH StefH added the question label Nov 29, 2019
@hsnsalhi
Copy link
Author

Yes, in fact my use case respects this spec (the example was just to show what I need)
But the problem is in the string to number conversion. the Response object does not accept StatusCode to be string, neither the method WithStatusCode in C# code.

@StefH StefH changed the title Extracting StatusCode from url.path StatusCode is defined as integer (string is not possible) Nov 29, 2019
@StefH
Copy link
Collaborator

StefH commented Nov 29, 2019

Correct. The reason that you cannot use a string because it should always be an integer. So what issue do you have with this?

@hsnsalhi
Copy link
Author

In this case, is there a way to extract the status code from the url ?
example:
I send https://localhost/test/statuscode401
And the response should be with status code 401

@StefH
Copy link
Collaborator

StefH commented Nov 29, 2019

If you send something like https://localhost/test/statuscode/401, then you can get the 401 using:
request.PathSegments.[2].

However, at this moment, you cannot set this to the StatusCode because only integer is allowed.

This could be implemented with a new cast extension on Handlebars. I can investigate this.
Also allowing a the code to be converted from string to integer could be an option.
(BTW I need to check if the StatusCode is actually processed by Handlebars...)

@StefH
Copy link
Collaborator

StefH commented Nov 29, 2019

BTW just posting a new mapping to the __admin is possible with a string as StatusCode:

{
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "RegexMatcher",
            "Pattern": "/statuscode/(\\d+)"
          }
        ]
      },
      "Methods": [
        "post"
      ]
    },
    "Response": {
      "StatusCode": "401",
      "BodyAsJson": {
        "path": "{{request.path}}"
      },
      "UseTransformer": true
    }
}

@hsnsalhi
Copy link
Author

Actually it's the workaround I'm working with.
I create a mapping for every possible status code returned by the mocked API
Thank you for your help

@StefH
Copy link
Collaborator

StefH commented Nov 30, 2019

@hsnsalhi
Can you try WireMock.Net.1.0.37-ci-12253.nupkg from MyGet ? (https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions)

@StefH
Copy link
Collaborator

StefH commented Dec 3, 2019

@hsnsalhi Can you try if this version solves your issue?

@StefH
Copy link
Collaborator

StefH commented Dec 5, 2019

@hsnsalhi Can you please test if that version solves your problem?

1 similar comment
@StefH
Copy link
Collaborator

StefH commented Dec 10, 2019

@hsnsalhi Can you please test if that version solves your problem?

@StefH
Copy link
Collaborator

StefH commented Dec 17, 2019

@hsnsalhi Can you please test?

@StefH StefH closed this as completed Dec 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants